Example of calling WebService with JavaScript _javascript tips

Source: Internet
Author: User
The steps are as follows:

Download Microsoft HTC components: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/ Webservice/default.asp

Web Service WSDL:

<?xml version= "1.0" encoding= "UTF-8"?>
<definitions name= "Ws_system_login_select" targetnamespace= "Scrm4u_service" "xmlns:tns=" xmlns: wsdlns= "Scrm4u_service" xmlns:soap= "http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd= "http://www.w3.org/2001/" XmlSchema "xmlns=" http://schemas.xmlsoap.org/wsdl/"xmlns:tns1=" Scrm4u_service ">
<document>
<URL>http://192.168.2.148:8080/SCRM4U_SERVICE/servlet/HLP_PWS_SYSTEM_LOGIN_SELECT.htm</URL>
<line>?</line>
</document>
<types>
<schema targetnamespace= "Scrm4u_service" xmlns= http://www.w3.org/2001/XMLSchema "xmlns:soap-enc=" http:// schemas.xmlsoap.org/soap/encoding/"elementformdefault=" qualified ">
<complextype name= "W_s_login_user_info" >
<all>
<element name= "W_v_usid" type= "xsd:string" >
</element>
<element name= "W_v_user_mei" type= "xsd:string" >
</element>
<element name= "W_v_usid2" type= "xsd:string" >
</element>
<element name= "w_v_rem_phr" type= "xsd:string" >
</element>
<element name= "W_v_rem_res" type= "xsd:string" >
</element>
<element name= "W_v_usr_ast" type= "xsd:string" >
</element>
<element name= "W_v_psn_no" type= "xsd:string" >
</element>
<element name= "w_v_menurole_id" type= "xsd:string" >
</element>
<element name= "w_v_usr_ast_nm" type= "xsd:string" >
</element>
<element name= "W_n_usr_ast_pri_ord" type= "Xsd:long" >
</element>
<element name= "w_v_school_id" type= "xsd:string" >
</element>
<element name= "W_v_exm_no" type= "xsd:string" >
</element>
<element name= "W_v_scrg_no" type= "xsd:string" >
</element>
<element name= "W_v_grntr_psn_no" type= "xsd:string" >
</element>
</all>
</complexType>
<element name= "Ws_system_login_select. Execute ">
<complexType>
<sequence>
<element minoccurs= "1" maxoccurs= "1" name= "P_v_userid" type= "xsd:string"/>
<element minoccurs= "1" maxoccurs= "1" name= "P_v_password" type= "xsd:string"/>
</sequence>
</complexType>
</element>
<element name= "Ws_system_login_select. Executeresponse ">
<complexType>
<sequence>
<element minoccurs= "1" maxoccurs= "1" name= "P_s_login_user_info" type= "Tns1:w_s_login_user_info"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name= "Ws_system_login_select. Executesoapin ">
<part name= "Parameters" element= "Tns:ws_system_login_select". Execute "/>
</message>
<message name= "Ws_system_login_select. Executesoapout ">
<part name= "Parameters" element= "Tns:ws_system_login_select". Executeresponse "/>
</message>
<porttype name= "Ws_system_login_selectsoapport" >
<operation name= "Execute" >
<input message= "Wsdlns:ws_system_login_select. Executesoapin "/>
<output message= "Wsdlns:ws_system_login_select. Executesoapout "/>
</operation>
</portType>
<binding name= "ws_system_login_selectsoapbinding" type= "Wsdlns:ws_system_login_selectsoapport" >
<soap:binding style= "Document" transport= "Http://schemas.xmlsoap.org/soap/http"/>
<operation name= "Execute" >
<soap:operation soapaction= "Scrm4u_serviceaction/aws_system_login_select. Execute "/>
<input>
<soap:body use= "literal"/>
</input>
<output>
<soap:body use= "literal"/>
</output>
</operation>
</binding>
<service name= "Ws_system_login_select" >
<port name= "Ws_system_login_selectsoapport" binding= "wsdlns:ws_system_login_selectsoapbinding" >
<soap:address location= "Http://192.168.2.148:8080/SCRM4U_SERVICE/servlet/aws_system_login_select"/>
</port>
</service>
</definitions>

Demo Code:

<script language= "JavaScript" ....
function Doservice (userid, password) ... {

Service.useservice ({WebService Location},{webservice class name})
Service.useservice ("http://192.168.2.148:8080/SCRM4U_SERVICE/servlet/aws_system_login_select?wsdl", "ws_system_ Login_select ");
Service. Service.callservice ({webmethod},{input parameters needed})
Service. Ws_system_login_select.callservice (Showresult, "Execute", userid, password);
}

function Showresult (Result) ... {

alert (Result.value.W_V_USER_MEI);
}
</script>
<body>
<div id= "service" style= "Behavior:url (./webservice.htc)" ></div>
Username:<input type= "text" id= "userid" name= "userid" >
<br/>
Password:<input type= "text" id= "PassWord" name= "PassWord" >
<br/>
<input type= "button" value= "Callwebservice" onclick= "Doservice (" document.getElementById "). Value, document.getElementById (' password '). Value) "/>
</body>
Note: If the service return value type is string, the value can be fetched directly with Result.value.

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.