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. Only key code is placed below
$ (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;
}
I've been learning a lot about jquery recently, and I've found many examples of jquery accessing. NET WebService. As webservice this interface should be generic, why doesn't anyone have an example of Java? I'm interested in this.