Java Reference
In-Depth Information
Connecting to a SAAJ Endpoint Without a WSDL
Problem
You want to create a connection to a SAAJ endpoint. You know the data structure required for
messages, but it doesn't present a WSDL, and Service.create requires a WSDL.
Solution
Create a SOAPConnectionFactory and use it to get a SOAPConnection object.
Discussion
The SOAP connection allows you to send a SOAP message to a resource at the end of a
URL. This is convenient to use in any situation, but necessary if that service does not have
a defined WSDL. That's because calling Service.create requires passing in the location of
the WSDL. It may be rare that you don't have a WSDL with a SOAP-based service, but it
does happen, and you'll be prepared.
//Prepare Request
SOAPMessage request =
MessageFactory.newInstance().createMessage();
//add data to request SOAP Message here...
//Create connection object
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connection = scf.createConnection();
//Create an endpoint to invoke
URL endpoint = new URL("http://localhost:8080/" +
"SAAJProvider/SAAJProviderServlet");
// Send request to endpoint, get response
SOAPMessage response = connection.call(request, endpoint);
To create a connection to a web service that does not expose a WSDL, you can use the
SOAPConnection class to communicate directly with the remote resource. First, create a
SOAP message for your request as you normally would, and populate its body with data as ne-
cessary. Then get an instance of the SOAPConnection object using the SOAPConnectionFact-
ory class. You then create a URL object representing the remote resource (servlet) you want to
Search WWH ::




Custom Search