Sie sind auf Seite 1von 3

Java Web Services Up and Running 1. SOAP : Simple Object access protocol 2. SOA: Service Oriented Architecture. 3.

Webservices: SOAP/RESTful 4. SOAP Based Web Services: XML messages are communicated between client an d server. 5. Message based communication between client and server is called Message Exchange pattern 6. RESTful: Representational State Transfer 7. RESTful WebServices: HTTP request & XML response etc. 8. SOAP webservice over HTTP is a special case of RESTful WEbservice 9. The Language in which the consumer is written is immaterial. ----------------EXAMPLE 1-------------------------------------In Example1, we create 3 files: ---------------File1:HelloWordInterface.java package ch01.hw; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style=Style.RPC) public interface HelloWordInterface { @WebMethod String GetHelloWorldString(String szName); } ---------------File2: HelloWorld.java package ch01.hw; import javax.jws.WebService; @WebService(endpointInterface="ch01.hw.HelloWordInterface") public class HelloWorld implements HelloWordInterface { public String GetHelloWorldString(String szName) { return "Hello World! " + szName + "!"; } } ---------------File3: HelloWorldPublisher.java package ch01.hw; import javax.xml.ws.Endpoint; public class HelloWorldPublisher { public static void main(String[] args) { Endpoint.publish("http://localhost:9999/helloworld",new HelloWor ld()); } } -------------For Compilation... a) create these three files in folder ch01\hw

b) from the parent folder of ch01 , call javac ch01\hw\*.java And then we can execute the HelloWorldPublisher as follows:java ch01.hw.HelloWor ldPublisher and for seeing the WSDL of the file created : http://localhost:9999/helloworld?wsdl :) ---------------------------------------------------------------------10. http://localhost:9999/helloworld?wsdl, URL is called service endpoint. It in forms the client as to where the service can be accessed. 11.In the WSDL thats displayed, - <portType name="HelloWordInterface"> - <operation name="GetHelloWorldString"> <input message="tns:GetHelloWorldString" /> <output message="tns:GetHelloWorldStringResponse" /> </operation> </portType> tells the methods exposed by the endpoint. ------------------The Client For Example 1--------------------------package ch01.hw; import javax.xml.namespace.QName; import javax.xml.ws.Service; import java.net.URL; class HelloWorldClient { public static void main (String args[]) throws Exception { //First the Web service URL via normal java.net.url class. URL url = new URL("http://localhost:9999/helloworld?wsdl"); //arg1 = URI, arg2= Service name ... both as published in the ws dl. QName qname = new QName("http://hw.ch01/","HelloWorldService"); //arg1 = URI, arg2 = Port name from the WSDL Service service = Service.create(url,qname); HelloWordInterface hwObj = service.getPort(HelloWordInterface.cl ass); System.out.println(hwObj.GetHelloWorldString("udai")); } } ----> In this, the URI name & Servicename is from wsdl: targetNamespace="http:// hw.ch01/" name="HelloWorldService"> ----> PortTypeName is also from WSDL : <portType name="HelloWordInterface"> This is used for the interface name in the above scenario. --------------------------------------------12. In SOAP based web services, the XML Schema based type system is the default

type system that mediates between the client types and the service types.

Das könnte Ihnen auch gefallen