I took a closer look at several examples of people and found the problem. It is well known that WebService is compliant with the SOAP protocol, so why are examples of parameter passes in JSON format? NET WebService compatible JSON format, while Java is Standard WebService, incompatible with JSON. It seems that net has harmed everyone. So I took a closer look at the WSDL file and made an example. The key code is placed below.
Copy Code code as follows:
$ (function () {
$ ("#btnWs"). Click (btnajaxpost);
});
function Btnajaxpost (event) {
$.ajax ({
Type: "POST",
ContentType: "Text/xml",
URL: "Http://*****/webservicetest/services/helloworldservice",
Data:getpostdata (),//This should not be in JSON format
DataType: ' xml ',//Here is set to XML or not. Setting the JSON format will make the return value NULL
Success:function (XML) {
Make XML parsing of the results.
Browser judgment (ie and non ie are completely different)
if ($.browser.msie) {
$ ("#result"). Append (Xml.getelementsbytagname ("Ns1:out") [0].childnodes[0].nodevalue+ "<br/>");
}
else{
$ (XML). Find (' out '). each (function () {
$ ("#result"). Append ($ (this). Text () + "<br/>");
})
}
},
Error:function (x, E) {
Alert (' ERROR: ' +x.responsetext);
},
Complete:function (x) {
Alert (' Complete: ' +x.responsetext);
}
});
}
Defines the parameters that satisfy the SOAP protocol.
function Getpostdata ()
{
According to the WSDL parsing SayHelloWorld is the method name, parameters is the passed-in parameter name
var postdata= "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>";
postdata+= "<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/\ ">";
postdata+= "<soap:body><sayhelloworld xmlns=\" http://tempuri.org/\ ">";
postdata+= "<parameters>" +$ ("#txtName"). Val () + "</parameters>";
postdata+= "</sayHelloWorld></soap:Body>";
postdata+= "</soap:Envelope>";
return postdata;
}
Complete Example SVN address: http://theyounglearningmaterials.googlecode.com/svn/trunk/JavaWebServices/WebServiceTest/
All the examples I have learned in the future will be put in the http://theyounglearningmaterials.googlecode.com/svn/trunk/to facilitate management to prevent loss.