我用 Delphi 开发了一个小型独立网络服务器。程序如下:
function sum(a,b:string):string;stdcall;
begin
result:=a+b;
end;
如何在Vue JS中调用它?
网络服务 URL 是
http://127.0.0.1:8080/soap/iservice1
WSDL 文档:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" name="Iservice1service"
targetNamespace="http://tempuri.org/">
<script/>
<message name="sum0Request">
<part name="a" type="xs:string"/>
<part name="b" type="xs:string"/>
</message>
<message name="sum0Response">
<part name="return" type="xs:string"/>
</message>
<portType name="Iservice1">
<operation name="sum">
<input message="tns:sum0Request"/>
<output message="tns:sum0Response"/>
</operation>
</portType>
<binding name="Iservice1binding" type="tns:Iservice1">
<binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sum">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:service1Intf-Iservice1#sum"
style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:service1Intf-Iservice1"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:service1Intf-Iservice1"/>
</output>
</operation>
</binding>
<service name="Iservice1service">
<port name="Iservice1Port" binding="tns:Iservice1binding">
<address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://localhost:8080/soap/Iservice1"/>
</port>
</service>
</definitions>
vue 代码:
axios({
method: 'post',
url: webservice_url,
data: data_to_send
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
现在你能告诉我 url 是什么吗(在 vue 代码)请?
SOAP 服务的 HTTP 端点是
http://localhost:8080/soap/Iservice1
调用此服务上的“sum”操作的 SOAP 请求可能如下所示:
POST /soap/Iservice1 HTTP/1.1
Host: localhost:8080
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:service1Intf-Iservice1#sum"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:sum>
<tem:a>"string1"</tem:a>
<tem:b>"string2"</tem:b>
</tem:sum>
</soapenv:Body>
</soapenv:Envelope>
请注意,操作不是 URL 的一部分,而是在 HTTP 请求的 SOAPAction 标头中传递。
Vue.js 的示例可以在这里找到