asp.net WebService jquery Access instance

Source: Internet
Author: User
Tags soap wsdl

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.