How to consume rpc-encoded SOAP Web Service with Java -
is there way consume soap web service java using:
- the soapaction required (for example methodname called "find")
- the url of web service
- header authentication (username , password)
- in end output results
i have example request xml file consuming php can't find proper way on java.
[update: web service's wsdl style rpc/encoded]
[update #2: can find how solved problem below (by using java stubs generated ides)]
you can use java.net.httpurlconnection
send soap messages. e.g.:
public static void main(string[] args) throws exception { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<soap:envelope xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n" + " <soap:body>\r\n" + " <conversionrate xmlns=\"http://www.webservicex.net/\">\r\n" + " <fromcurrency>usd</fromcurrency>\r\n" + " <tocurrency>cny</tocurrency>\r\n" + " </conversionrate>\r\n" + " </soap:body>\r\n" + "</soap:envelope>"; authenticator.setdefault(new authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication("username", "password".tochararray()); } }); url url = new url("http://www.webservicex.net/currencyconvertor.asmx"); urlconnection conn = url.openconnection(); conn.setdooutput(true); conn.setrequestproperty("content-type", "text/xml; charset=utf-8"); conn.setrequestproperty("soapaction", "http://www.webservicex.net/conversionrate"); // send request xml outputstream outputstream = conn.getoutputstream(); outputstream.write(xml.getbytes()); outputstream.close(); // read response xml inputstream inputstream = conn.getinputstream(); scanner sc = new scanner(inputstream, "utf-8"); sc.usedelimiter("\\a"); if (sc.hasnext()) { system.out.print(sc.next()); } sc.close(); inputstream.close(); }
Comments
Post a Comment