3

I would like to send a number to a SOAP "server"(I don't know if I can call it a server, correct me if I'm wrong) and receive a response using HTML, I've seen many questions with answers containing examples of sending an XML request such as below, but I have no idea on how to receive and see a response on HTML, sorry I'm new to SOAP.

P.S.: Of course, by HTML I meant JavaScript within the HTML :P


Server: Here

Thanks in Advance!

<html>

<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://192.168.0.251:9080/wsa/wsa1', true);

            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:services-progress-com:notavailable">' +
                '<soapenv:Header/>' +
                '<soapenv:Body>' +
                '<urn:lnestagio>' +
                '<urn:vvalor>5</urn:vvalor>' +
                '</urn:lnestagio>' +
                '</soapenv:Body>' +
                '</soapenv:Envelope>';

            xmlhttp.onreadystatechange = function() {
                    if (xmlhttp.readyState == 4) {
                        if (xmlhttp.status == 200) {

                            alert('done use firebug to see response');
                        }
                    }
                }
                // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);
            // send request
            // ...
        }
    </script>
</head>

<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
<html>

SOAP's XML from my server

    <wsdl:definitions xmlns:tns="urn:services-progress-com:ys:server" xmlns:S2="urn:services-progress-com:sys:server:Estagio" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:prodata="urn:schemas-progress-com:xml-prodata:0001" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:S1="urn:soap-fault:details" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Estagio" targetNamespace="urn:services-progress-com:sys:server">
<wsdl:documentation>
Author=sys, EncodingType=DOC_LITERAL, WSA_Product=10.2B07 - N/A
</wsdl:documentation>
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="urn:soap-fault:details">
<element name="FaultDetail">
<complexType>
<sequence>
<element name="errorMessage" type="xsd:string"/>
<element name="requestID" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:services-progress-com:sys:server:Estagio">
<element name="lnestagio">
<complexType>
<sequence>
    <element name="vvalor" nillable="true" type="xsd:decimal"/> <!-- Here I think he gets the number I sent -->
</sequence>
</complexType>
</element>
<element name="lnestagioResponse">
<complexType>
<sequence>
<element name="result" nillable="true" type="xsd:string"/>
<element name="vcalc" nillable="true" type="xsd:decimal"/> <!-- And it returns the number multiplied by 2 -->
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="FaultDetailMessage">
<wsdl:part name="FaultDetail" element="S1:FaultDetail"/>
</wsdl:message>
<wsdl:message name="Estagio_lnestagio">
<wsdl:part name="parameters" element="S2:lnestagio"/>
</wsdl:message>
<wsdl:message name="Estagio_lnestagioResponse">
<wsdl:part name="parameters" element="S2:lnestagioResponse"/>
</wsdl:message>
<wsdl:portType name="EstagioObj">
<wsdl:operation name="lnestagio">
<wsdl:input message="tns:Estagio_lnestagio"/>
<wsdl:output message="tns:Estagio_lnestagioResponse"/>
<wsdl:fault name="EstagioFault" message="tns:FaultDetailMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EstagioObj" type="tns:EstagioObj">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="lnestagio">
<soap:operation soapAction="" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="EstagioFault">
<soap:fault name="EstagioFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EstagioService">
<wsdl:port name="EstagioObj" binding="tns:EstagioObj">
<wsdl:documentation/>
<soap:address location="http://localhost:9080/wsa/wsa1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Kyle
  • 1,568
  • 2
  • 20
  • 46
  • Rather than reinvent the wheel have you considered using one of the existing libraries? e..g http://javascriptsoapclient.codeplex.com/ – justAnotherUser Feb 18 '15 at 13:01

1 Answers1

6

Well, a SOAP server is designed to receive SOAP requests and send SOAP responses.

Since SOAP is basically XML, instead of expecting an HTML response from the server, it would be more appropriate to look for a mean to parse the XML of the SOAP response and display it in HTML.

But as I'm typing this answer, I think you may have misunderstood the goal of a SOAP server. It seems to me that you want to display the raw SOAP response directly to the client browser. But a SOAP server is not intended to work that way.

Typically a SOAP server is used by another server, by doing a SOAP request to it and then parsing the SOAP response. And this "other server" may be, for example, an HTTP server.

Let's take an example. I want to know the weather forecast of my city for tomorrow. I go to dummyweatherforecast.com and type the name of my city in the search field. But dummyweatherforecast.com does not store all the weather forecasts by itself. It may instead contact a SOAP server (specifically designed to provide weather forecasts) with a SOAP request containing the name of my city. The SOAP server returns a SOAP response with different weather information (sunny/cloudy, temperature, etc.) and then dummyweatherforecast.com processes this SOAP response (that is, as a reminder, XML) to display it to the client with a beautiful sentence like "It will be sunny tomorrow, with 86°F. Take your swimsuit !" ornamented with a beautiful sun iconography.

As you see, the client doesn't even know that a SOAP communication is held between dummyweatherforecast.com and the SOAP server. And this how SOAP is used : by servers themselves, and rarely directly by clients. This is what we call "web services", even though this term refers to a more general set of technologies used to make computers talk to each others.

I hope this brightened your mind a little bit.

PS : by the way, the link you give for your server points to an IP not available publicly (192.168 adresses are for private networks).

sylozof
  • 86
  • 5
  • 1
    It really did, Thanks for your answer, I'll put the XML code – Kyle Feb 18 '15 at 13:41
  • 1
    Let me clarify a little bit, I send a number to this server and it must return me (myNumber*2), it works on SoapUI 5.0.0 and I want to do it on my html app. I just want to receive the number not the raw XML. – Kyle Feb 18 '15 at 13:48
  • 1
    If you really want to call the SOAP server directly from you HTML, so the link provided by justAnotherUser in the comment above is a solution. But if you want to comply to what I explained earlier, then your client HTML should call, via a form or a link, a server script written in PHP (or another language you're at ease with) that will contact the SOAP server and parse the SOAP response. Then this server script will return the result to the client in HTML. PHP as built-in SOAP functions for that. – sylozof Feb 18 '15 at 14:01
  • 1
    so I can't do it like I was trying to do? (using a HTML application and sending it) – Kyle Feb 18 '15 at 15:42
  • 1
    How can I connect my app with the SOAP server then? – Kyle Feb 18 '15 at 15:56
  • In your JS code sample of your initial question, instead of the "alert('done use firebug to see response');" piece of code, you should analyze the SOAP response provided by the server and find in the XML content the expected result. But as @justAnotherUser said, this would be like reinventing the wheel since JS libraries for that kind of process already exist. He gave a link to one of them, but there certainly are more. But again, using SOAP server directly from a client is not recommended (see the end of this [answer](http://stackoverflow.com/a/125062/3300762) from another topic). – sylozof Feb 19 '15 at 01:04
  • 1
    How can I use http://javascriptsoapclient.codeplex.com/, I downloaded it, but how can I use it? – Kyle Feb 19 '15 at 13:22