我如何发送SOAP请求并使用HTML接收响应? [英] How can I send a SOAP request and receive a response using HTML?

查看:175
本文介绍了我如何发送SOAP请求并使用HTML接收响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向一个 SOAP 服务器发送一个号码(我不知道是否可以将它称为服务器,如果我错了,请纠正我的错误)并接收响应 HTML ,我看到很多问题,其中包含发送XML请求的示例(如下),但我不知道如何接收和查看 HTML 上的响应,很抱歉,我是 SOAP 的新手。



PS:当然,通过HTML我是指HTML内的JavaScript:P




服务器:这里

非常感谢!

 < HTML>< HEAD> < title> SOAP JavaScript客户端测试< / title> < script type =text / javascript>函数soap(){var xmlhttp = new XMLHttpRequest(); xmlhttp.open('POST','http://192.168.0.251:9080/wsa/wsa1',true); //建立SOAP请求var sr ='<?xml version =1.0encoding =utf-8?>'+'< soapenv:Envelope xmlns:soapenv =http://schemas.xmlsoap.org &soap / envelope /xmlns:urn =urn:services-progress-com:notavailable>'+'< soapenv:Header />'+'< soapenv:Body>'+'< urn: >'+'< 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'); }}} //发送POST请求xmlhttp.setRequestHeader('Content-Type','text / xml'); xmlhttp.send(SR); //发送请求// ...}< / script>< / head>< body> < form name =Demoaction =method =post> < DIV> < input type =buttonvalue =Soaponclick =soap(); /> < / DIV> < / form>< / body>< html>  

$ b

来自我的服务器的SOAP XML

 < wsdl:definitions xmlns:tns =urn:services -progress-com:ys:serverxmlns:S2 =urn:services-progress-com:sys:server:Estagioxmlns:soapenc =http://schemas.xmlsoap.org/soap/encoding/xmlns: xsd =http://www.w3.org/2001/XMLSchemaxmlns:prodata =urn:schemas-progress-com:xml-prodata:0001xmlns:soap =http://schemas.xmlsoap.org / wsdl / soap /xmlns:wsdl =http://schemas.xmlsoap.org/wsdl/xmlns:S1 =urn:soap-fault:detailsxmlns =http://schemas.xmlsoap.org/ wsdl /name =EstagiotargetNamespace =urn:services-progress-com:sys:server> 
< wsdl:documentation>
Author = sys,EncodingType = DOC_LITERAL,WSA_Product = 10.2B07 - 不适用
< / wsdl:documentation>
< wsdl:types>
< schema xmlns =http://www.w3.org/2001/XMLSchemaelementFormDefault =unqualifiedtargetNamespace =urn:soap-fault:details>
< element name =FaultDetail>
< complexType>
< sequence>
< element name =errorMessagetype =xsd:string/>
< element name =requestIDtype =xsd:string/>
< / sequence>
< / complexType>
< / element>
< / schema>
< element name =lnestagio>
< complexType>
< sequence>
< element name =vvalornillable =truetype =xsd:decimal/> <! - 这里我认为他得到了我发送的号码 - >
< / sequence>
< / complexType>
< / element>
< element name =lnestagioResponse>
< complexType>
< sequence>
< element name =resultnillable =truetype =xsd:string/>
< / sequence>
< / complexType>
< / element>
< / schema>
< / wsdl:types>
< wsdl:message name =FaultDetailMessage>
< wsdl:part name =FaultDetailelement =S1:FaultDetail/>
< / wsdl:message>
< wsdl:message name =Estagio_lnestagio>
< wsdl:part name =parameterselement =S2:lnestagio/>
< / wsdl:message>
< wsdl:message name =Estagio_lnestagioResponse>
< wsdl:part name =parameterselement =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 =EstagioFaultmessage =tns:FaultDetailMessage/>
< / wsdl:operation>
< / wsdl:portType>
< wsdl:binding name =EstagioObjtype =tns:EstagioObj>
< soap:binding style =documenttransport =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 =EstagioFaultuse =literal/>
< / wsdl:fault>
< / wsdl:operation>
< / wsdl:binding>
< wsdl:service name =EstagioService>
< wsdl:port name =EstagioObjbinding =tns:EstagioObj>
< wsdl:documentation />
< soap:address location =http:// localhost:9080 / wsa / wsa1/>
< / wsdl:port>
< / wsdl:service>
< / wsdl:definitions>


解决方案

好的,SOAP服务器旨在接收SOAP请求并发送SOAP响应。

由于SOAP基本上是XML,而不是期待服务器发出HTML响应,所以寻找解析SOAP响应的XML的方法更为合适,并且以HTML格式显示。



但是当我输入这个答案时,我想你可能误解了SOAP服务器的目标。在我看来,你想直接向客户端浏览器显示原始的SOAP响应。但是SOAP服务器并不打算以这种方式工作。

通常,另一台服务器使用SOAP服务器,通过对其执行SOAP请求,然后解析SOAP响应。而这个其他服务器可能是,例如,一个HTTP服务器。



我们举个例子吧。我想知道明天我的城市的天气预报。我前往dummyweatherforecast.com并在搜索字段中键入我的城市名称。但是,dummyweatherforecast.com并不存储所有的天气预报。它可以改为联系SOAP服务器(专门设计用于提供天气预报)并发送包含我所在城市名称的SOAP请求。 SOAP服务器返回一个包含不同天气信息(阳光/阴天,温度等)的SOAP响应,然后dummyweatherforecast.com处理这个SOAP响应(也就是提醒XML),以便用美丽的句子将其显示给客户端例如明天晴天,86°F,带上泳衣!装饰着美丽的太阳图像。



正如您所看到的,客户端甚至不知道dummyweatherforecast.com和SOAP服务器之间是否存在SOAP通信。以及SOAP如何使用:服务器本身,很少直接由客户端使用。这就是我们所说的网络服务,即使这个术语指的是用于使计算机彼此交谈的更一般技术集合。



我希望这个变亮PS:顺便说一下,你为服务器提供的链接指向一个不能公开的IP地址(192.168地址用于专用网络)。

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>

解决方案

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

这篇关于我如何发送SOAP请求并使用HTML接收响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆