3. Use the Web servie Client
After a Web Service is deployed on the server, it can be called by other applications. Calling a Web Service is actually very simple and requires no special settings. For example, we used http: // localhost: 8080/axis/helloworld. JWS? WSDL access is a kind of Web servicede call. Of course, this statement is not strict enough. The method provided by the Web Service is called. We use this method to call: http: // localhost: 8080/axis/helloworld? Method = sayhello & username = Brookes. The following page is displayed:
<? XML version = "1.0" encoding = "UTF-8"?>
<Soapenv: envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
<Soapenv: Body>
<Sayhelloresponse soapenv: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/">
<Sayhelloreturn xsi: TYPE = "XSD: string"> Hello Brookes, welcome to my web service. </sayhelloreturn>
</Sayhelloresponse>
</Soapenv: Body>
</Soapenv: envelope>
This is a standard XML response to the SOAP protocol. The key is the <sayhelloreturn> element, which is the response of Web servcie to the sayhello method! We only need to parse this XML file to get the desired response. (For more information, see XMLHttpRequest)
Apache axis supports three ways for clients to access web services:
1. dynamic invocation interface (DiI) dynamic call interface
2. Dynamic proxy
3. stubs Pile
[Note] I have seen that the above three methods are listed as the three "development and deployment methods" of Web servcie. I think this statement is inappropriate. If development involves client development, the deployment seems to be more specific to the server. My understanding is also a family of words. please correct me.
Let's first look at the DiI method. The core code is as follows (we used the previous helloworld Web Service ):
Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Import javax. xml. namespace. QNAME;
Public class wstest ...{
Public static void main (string [] ARGs )...{
Try ...{
String endpoint = "http: // localhost: 8080/axis/helloworld. JWS ";
Service = new service ();
Call call = NULL;
Call = (CALL) service. createcall ();
Call. setoperationname (New QNAME ("http: // localhost: 8080/axis/helloworld. JWS", "sayhello "));
Call. settargetendpointaddress (New java.net. URL (endpoint ));
String response = (string) Call. Invoke (new object []... {"Brookes "});
System. Out. println ("return value is:" + response );
} Catch (exception ex)... {ex. printstacktrace ();}
}
}
Run the program and obtain the following output information:
Return Value is: Hello Brookes, welcome to my web service.
It's so easy to access the Web service using DiI!