JavaScript 和 Web 服务 WSDL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11179780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript and web services WSDL
提问by Mpampinos Holmens
i want to call a web service using javascript. i have a form where i give some parameters (int) and want to get the result how can do it using javascript?
我想使用 javascript 调用 Web 服务。我有一个表格,我在其中提供了一些参数 (int) 并想获得结果如何使用 javascript 来实现?
here are the WSDL files
这是 WSDL 文件
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://lapack.sws4hpsc.uth/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://lapack.sws4hpsc.uth/" name="DgesvSampleWsService">
<ns1:Policy xmlns:ns1="http://www.w3.org/ns/ws-policy" wsu:Id="DgesvSampleWsPortBinding_MTOM_Policy">
<ns1:ExactlyOne>
<ns1:All>
<ns2:OptimizedMimeSerialization xmlns:ns2="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" ns1:Optional="true"/>
</ns1:All>
</ns1:ExactlyOne>
</ns1:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://lapack.sws4hpsc.uth/" schemaLocation="http://83.212.96.238:8080/DgesvSampleWs/DgesvSampleWsService?xsd=1"/>
</xsd:schema>
</types>
<message name="_dgesv">
<part name="parameters" element="tns:_dgesv"/>
</message>
<message name="_dgesvResponse">
<part name="parameters" element="tns:_dgesvResponse"/>
</message>
<portType name="DgesvSampleWs">
<operation name="_dgesv">
<input message="tns:_dgesv"/>
<output message="tns:_dgesvResponse"/>
</operation>
</portType>
<binding name="DgesvSampleWsPortBinding" type="tns:DgesvSampleWs">
<ns3:PolicyReference xmlns:ns3="http://www.w3.org/ns/ws-policy" URI="#DgesvSampleWsPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="_dgesv">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="DgesvSampleWsService">
<port name="DgesvSampleWsPort" binding="tns:DgesvSampleWsPortBinding">
<soap:address location="http://83.212.96.238:8080/DgesvSampleWs/DgesvSampleWsService"/>
</port>
</service>
</definitions>
and the second one
第二个
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://lapack.sws4hpsc.uth/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://lapack.sws4hpsc.uth/" name="DgtsvSampleWsService">
<ns1:Policy xmlns:ns1="http://www.w3.org/ns/ws-policy" wsu:Id="DgtsvSampleWsPortBinding_MTOM_Policy">
<ns1:ExactlyOne>
<ns1:All>
<ns2:OptimizedMimeSerialization xmlns:ns2="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" ns1:Optional="true"/>
</ns1:All>
</ns1:ExactlyOne>
</ns1:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://lapack.sws4hpsc.uth/" schemaLocation="http://83.212.96.238:8080/DgtsvSampleWs/DgtsvSampleWsService?xsd=1"/>
</xsd:schema>
</types>
<message name="_dgtsv">
<part name="parameters" element="tns:_dgtsv"/>
</message>
<message name="_dgtsvResponse">
<part name="parameters" element="tns:_dgtsvResponse"/>
</message>
<portType name="DgtsvSampleWs">
<operation name="_dgtsv">
<input message="tns:_dgtsv"/>
<output message="tns:_dgtsvResponse"/>
</operation>
</portType>
<binding name="DgtsvSampleWsPortBinding" type="tns:DgtsvSampleWs">
<ns3:PolicyReference xmlns:ns3="http://www.w3.org/ns/ws-policy" URI="#DgtsvSampleWsPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="_dgtsv">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="DgtsvSampleWsService">
<port name="DgtsvSampleWsPort" binding="tns:DgtsvSampleWsPortBinding">
<soap:address location="http://83.212.96.238:8080/DgtsvSampleWs/DgtsvSampleWsService"/>
</port>
</service>
</definitions>
回答by sashwat
Create a SOAP request and invoke the caller. ref:Simplest SOAP example
Get the response and parse the XML. ref:Parse XML using JavaScript
创建一个 SOAP 请求并调用调用者。 参考:最简单的 SOAP 示例
获取响应并解析 XML。 参考:使用 JavaScript 解析 XML
回答by Emeeus
Here a possible approach, assuming you put wsdl into a file request.wsdl
and assuming that the remote server is accessible and have Access-Control-Allow-Origin: *
header
这是一种可能的方法,假设您将 wsdl 放入文件request.wsdl
并假设远程服务器可访问并具有Access-Control-Allow-Origin: *
标头
//wsdl request
var client = new XMLHttpRequest();
client.open('GET', 'request.wsdl');
client.onreadystatechange = function () {
var request = client.responseText;//here the wsdl
//SOAP request
var client2 = new XMLHttpRequest();
client2.open('POST', 'http://83.212.96.238:8080/DgesvSampleWs/DgesvSampleWsService', true);
client2.onreadystatechange = function () {
if (client2.readyState == 4) {
if (client2.status == 200) {
console.log(client.responseText);//here the response
}
}
}
client2.setRequestHeader('Content-Type', 'text/xml');
client2.send(request);
}
client.send();
The idea is performing and ajax to call wsdl definitions and in it's callback, perform another ajax that call that you want to call. This domains http://83.212.96.238:808
it's not giving me response but I think the approach is valid.
这个想法是执行和 ajax 调用 wsdl 定义,并在它的回调中执行另一个你想要调用的调用的 ajax。这个域http://83.212.96.238:808
它没有给我回应,但我认为这种方法是有效的。