Wednesday, November 30, 2005

Sample Java SOAP client

Below is a sample Java SOAP client. Hope this comes in handy for someone looking for a sample. I will post some J2EE RPC style service clients as well as a J2EE application client. If anyone is interested in other clients wrote in different languages, just let me know.

/////////////////////////////////////////////////////////////////////////////////////////////////////

import java.util.*;
import java.net.URL;
import javax.xml.namespace.*;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;

class TestServiceClient {

public static void main (String [] args) throws Exception {

URL url = new URL("http://www.test.com/TestService")
QName svcName = new QName("http://com.test","TestService");
QName op = new QName("http://com.test/TestService","test")

ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(svcName);

Call call = (Call)service.createCall();
call.setTargetEndpointAddress(url.toString());
call.setOperationName(op);
call.setReturnType(XMLType.XSD_STRING);

String response = (String)call.invoke(new Object[] { });
System.out.println("response: " + response);

}

}

0 Comments:

Post a Comment

<< Home