How can I call a SOAP webserver method in Vue.js?

83 Views Asked by At

I developed a small stand alone webserver in Delphi. The procedure is as below:

function sum(a,b:string):string;stdcall;
begin
result:=a+b;
end;

How can I call it in Vue JS?

The web service URL is

http://127.0.0.1:8080/soap/iservice1

the WSDL document:

<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>

The vue codes:

    axios({
    method: 'post',
    url: webservice_url,
    data: data_to_send
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Now can you tell me what is the url (in vue code) please?

1

There are 1 best solutions below

2
mjn On

The HTTP endpoint for the SOAP service is

http://localhost:8080/soap/Iservice1

Here is how a SOAP request to invoke the "sum" operation on this service might look:

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>

Note that the operation is not part of the URL, but passed in the SOAPAction header of the HTTP request.

Examples for Vue.js can be found here

So the steps to invoke the sum operation using axios would be:

  1. define constants for URL, request body, and request headers (Content-Type and SOAPAction)

  2. invoke axios:

    axios({ url: url, method: 'POST', data: soapRequestBody, headers: headers, }) .then((response) => { this.response = response; console.log('Response', response); }) .catch((error) => { console.log('Error', error); });