0

I am new to SOAP , I want to call web service .
I have seen a tutorial for making soap request .
This is the Code

 MessageFactory mf = null; SOAPMessage sm = null; SOAPEnvelope envelope = null; MimeHeaders headers = null; SOAPBody body = null; SOAPElement requestData = null; SOAPElement requestDoc = null; CDATASection cdata = null; SOAPConnectionFactory sfc = null; SOAPConnection connection = null; URL requestUrl = null; SOAPMessage response = null; OutputStream os = null; String host = null; int port = 80; String path = null; String api_key = null; int socket_timeout = 0; String service_type = null; String baseXml = null; try { xmlChannelRequest = createChannelRequest(cmId, function, guId, password, estabId); mf = MessageFactory.newInstance(); sm = mf.createMessage(); envelope = sm.getSOAPPart().getEnvelope(); envelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelope/"); envelope.setPrefix("soapenv"); envelope.setAttribute("xmlns:tem", "http://tempuri.org/"); headers = sm.getMimeHeaders(); headers.addHeader("SOAPAction", "http://tempuri.org/IPublicChannelManagerService/RequestData"); body = envelope.getBody(); body.setPrefix("soapenv"); requestData = body.addChildElement("RequestData"); requestData.setPrefix("tem"); requestDoc = requestData.addChildElement("requestDocument", "tem", "http://tempuri.org/"); cdata = requestDoc.getOwnerDocument().createCDATASection("<Request>\n" + " <Authentication CMId=\"6438\" Function=\"31\" Guid=\"5594FB83-F4D4-431F-B3C5-EA6D7ASDSBA795\" Password=\"y656g321TR\"/>\n" + " <Establishment Id=\"297867\"/>\n" + " </Request>"); requestDoc.appendChild(cdata); System.out.println("---------------- SOAP Request ----------------------------"); sm.writeTo(System.out); sfc = SOAPConnectionFactory.newInstance(); connection = sfc.createConnection(); requestUrl = new URL("http://pp.xxx.yyyy.co.uk/zzzz.svc?wsdl"); response = connection.call(sm, requestUrl); 

This is working fine. My question is , is there any easy way , just like passing object to method and it creates , SOAP request .
ex : Just like JaxB , i will send a Bean , it will generate xml.

 outputStream = new ByteArrayOutputStream(); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(beanObject, outputStream); 

1 Answer 1

1

You should have the WSDL file before you make the request. Then just generate your specific classes using e.g. wsimport tool and then just call the JAX-WS webservice. You do not have to build the request by yourself in this way.

Have a look over this tutorial.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.