This section contains document style client examples.
package client;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.enum.Style;
import org.apache.axis.enum.Use;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPEnvelope;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.axis.utils.XMLUtils;
import java.util.Vector;
public class DIIDocClient
{
public static void main(String[] args)
{
try
{
/*
* NOTE: The web service uses document style
* eg:
*<service name="MyDocSample" provider="java:RPC" style="document" use="literal">
*/
String url = "http://localhost:8080/ws/services/MyDocSample";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
String param= "hello";
/*
*construct the XML document
*/
SOAPBodyElement[] input = new SOAPBodyElement[1];
input[0] = new SOAPBodyElement(XMLUtils.StringToElement("http://www.w3.org/2001/XMLSchema",
"echo", param));
Vector elems = (Vector) call.invoke( input );
SOAPBodyElement elem = (SOAPBodyElement) elems.get(0);
Element e = elem.getAsDOM();
System.out.println("returned value: " + XMLUtils.ElementToString(e)); }
catch (Throwable t)
{
t.printStackTrace();
}
}
}
In the above example, the XML in the request sent to the server is:
<?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> <xsd:echo>hello</xsd:echo> </soapenv:Body> </soapenv:Envelope>
If the example is RPC-style, the XML in the request sent to the server is:
<?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> <echo xmlns=""> <arg0 xsi:type="xsd:string">hello</arg0> </echo> </soapenv:Body> </soapenv:Envelope>
| Copyright © 2005. Sybase Inc. All rights reserved. |
|
|