web services - sending a SOAP message via HTTP in java -
i have following code:
string xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>" + "<soap-env:envelope xmlns:soap-env=\"http://www.w3.org/2003/05/soap-envelope\" " + "xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" " + "xmlns:ns1=\"http://org.apache.axis2/xsd\" " + "xmlns:ns=\"http://tfc\" " + "xmlns:wsaw=\"http://www.w3.org/2006/05/addressing/wsdl\" " + "xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" " + "xmlns:xs=\"http://www.w3.org/2001/xmlschema\"" + "xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" " + "xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" " + "xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\" " + "xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" " + "xmlns:xsd=\"http://www.w3.org/2001/xmlschema\" > " + "<soap-env:body>" + "<ns:calfare xmlns:ns=\"http://tfc\">" + "<ns:nonairport>1</ns:nonairport>" + "<ns:distance>20</ns:distance>" + "</ns:calfare>" + "</soap-env:body>" + "</soap-env:envelope>"; //create socket string hostname = "128.196.239.112"; int port = 8080; inetaddress addr = inetaddress.getbyname(hostname); socket sock = new socket(addr, port); //send header string path = "/locatorztaxifare/services/calculator.calculatorhttpsoap11endpoint/"; bufferedwriter wr = new bufferedwriter(new outputstreamwriter(sock.getoutputstream(),"utf-8")); // can use "utf8" compatibility microsoft virtual machine. wr.write("post " + path + " http/1.0\r\n"); wr.write("host: 128.196.239.112\r\n"); wr.write("content-length: " + xmldata.length() + "\r\n"); wr.write("content-type: text/xml; charset=\"utf-8\"\r\n"); wr.write("\r\n"); //send data wr.write(xmldata); wr.flush(); // response bufferedreader rd = new bufferedreader(new inputstreamreader(sock.getinputstream())); string line; while((line = rd.readline()) != null) system.out.println(line); } catch (exception e) { e.printstacktrace(); }
now it's giving me internal server error following response:
<?xml version='1.0' encoding='utf-8'?><soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:action></soapenv:header><soapenv:body><soapenv:fault><faultcode></faultcode><faultstring>com.ctc.wstx.exc.wstxunexpectedcharexception: unexpected character 'x' (code 120) excepted space, or '>' or "/>"
 @ [row,col {unknown-source}]: [1,390]</faultstring><detail /></soapenv:fault></soapenv:body></soapenv:envelope>
here's link wsdl
at glance, looks xml you're sending invalid. xml processor found 'x' when looking space, '>' or '/>'. so, fix payload.
yup...here is:
"xmlns:xs=\"http://www.w3.org/2001/xmlschema\"" + "xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" " +
that first line wrong, need add trailing space (like in second line).
mind, helps read error messages. said wrong. no real magic here.
Comments
Post a Comment