Java

Saturday, 16 March 2013

websevice jax ws rpc example


websevice jax-ws-rpc style:
-----------------------------------

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    HIBERNATE-ANNOTATIONS     SPRING-IOC       SPRING –AOP-SCHEMABASED   

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT.... 





NOTE:   1)  maven dependeccy pom.xml  , we can get from previous example.
              

SayHaiService .java
--------------

package madhav;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface SayHaiService {
    @WebMethod
    public String sayHai(String hai);
   
}

SayHaiServiceImpl .java
---------------
package madhav;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(endpointInterface = "madhav.SayHaiService")
public class SayHaiServiceImpl implements SayHaiService{

    @Override
    @WebMethod
    public String sayHai(String hai) {
        return hai;
    }

}


Publish .java
--------------

package madhav;
import javax.xml.ws.Endpoint;
public class Publish {
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/webservice-JAX-WS-RPC/sayhai", new SayHaiServiceImpl());
        System.out.println("say hai service is published");
    }

}




Client .java
---------------
package madhav;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class Client {
    public static void main(String[] args) {
        URL url = null;
        try {
            url = new URL("http://localhost:8080/webservice-JAX-WS-RPC/sayhai?wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        QName qname = new QName("http://madhav/",
                "SayHaiServiceImplService");

        Service service = Service.create(url, qname);

        SayHaiService sayHaiService = service.getPort(SayHaiService.class);

        System.out.println(sayHaiService.sayHai("hai how r u"));

    }

}
TUTIORALS FROM MADHAV:

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    HIBERNATE-ANNOTATIONS     SPRING-IOC       SPRING –AOP-SCHEMABASED   

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT....  



No comments:

Post a Comment