Not long before the company, wrote a Java call. NET write WebService results during the test with a variety of methods are not completed, always throw an exception, and finally directly using the SOAP message to make the call succeeded, the specific code is as follows, for reference only:
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.OutputStream;
Import java.net.HttpURLConnection;
Import java.net.MalformedURLException;
Import Java.net.URL;
Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
public class Querydatautil {
public static string Getopdetailstring (String regoinid,string regoinname,string signalname) throws exception{
String xml = "";
Xml= "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>";
XML + = "<soapenv:envelope xmlns:soapenv=\" http://schemas.xmlsoap.org/soap/envelope/\ "xmlns:soap=\"/HTTP// Www.w3.org/2003/05/soap-envelope\ "xmlns:tem=\" http://tempuri.org/\ "xmlns:soap-enc=\" http://schemas.xmlsoap.org /soap/encoding/\ "xmlns:xsi=\" http://www.w3.org/2001/xmlschema-instance\ "xmlns:xsd=\" http://www.w3.org/2001/ Xmlschema\ ">";
XML + = "<soapenv:Header/>";
XML + = "<soapenv:Body>";
XML + = "<tem:QueryDeviceRealData><tem:regionId>" +regoinid+ "</tem:regionid><tem:regionname > "+regoinname+" </tem:regionName><tem:signalName> "+signalname+" </tem:signalname></tem: Querydevicerealdata> ";
String xml1= "</soapenv:Body>";
xml1+= "</soapenv:Envelope>";
XML +=XML1;
String urlstring= "Http://IP: Port/xxxx?wsdl";
HttpURLConnection httpconn = null;
OutputStream out = null;
String returnxml= "";
Set up batch Numbers
DateFormat df = new SimpleDateFormat ("Yyyymmddhhmmss");
String s= Df.format (New Date ());
System.out.println ("Start");
Httpconn = (httpurlconnection) new URL (urlstring). OpenConnection ();
Httpconn.setrequestproperty ("Content-type", "text/xml; Charset=utf-8 ");
Httpconn.setrequestproperty ("SOAPAction", "xxx");
Httpconn.setrequestmethod ("POST");
Httpconn.setdooutput (TRUE);
Httpconn.setdoinput (TRUE);
Httpconn.connect ();
out = Httpconn.getoutputstream (); Get output Stream Object
Httpconn.getoutputstream (). Write (Xml.getbytes ()); The SOAP request character stream that will commit the server is written to the output stream
Out.flush ();
Out.close ();
int code = Httpconn.getresponsecode (); Used to get the server response status
String tempstring = null;
StringBuffer sb1 = new StringBuffer ();
if (code = = HTTPURLCONNECTION.HTTP_OK) {
BufferedReader reader = new BufferedReader (New InputStreamReader (Httpconn.getinputstream (), "UTF-8"));
while ((tempstring = Reader.readline ()) = null) {
Sb1.append (tempstring);
}
if (null! = Reader) {
Reader.close ();
}
} else {
BufferedReader reader = new BufferedReader (New InputStreamReader (Httpconn.geterrorstream (), "UTF-8"));
Read one line at a time until NULL is read to the end of the file
while ((tempstring = Reader.readline ()) = null) {
Sb1.append (tempstring);
}
if (null! = Reader) {
Reader.close ();
}
}
Response message
Returnxml=sb1.tostring ();
System.out.println ("returnopdetail===" +returnxml);
return returnxml;
}
}
I hope you have a lot of suggestions, huh?
Troubleshoot Java access. netwebservice FAQ