我想发送一个数字到SOAP“服务器”(我不知道我是否可以称它为服务器,如果我错了请纠正我)并使用接收响应HTML,我看到很多问题的答案都包含发送 XML 请求的示例,如下所示,但我不知道如何在 HTML 上接收和查看响应,抱歉,我是 SOAP 的新手。
P.S.:当然,对于 HTML,我指的是 HTML 中的 JavaScript :P
服务器:Here
提前致谢!
<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>
来 self 的服务器的 SOAP 的 XML
<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>
最佳答案
好吧,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 度。带上你的泳衣!”装饰着美丽的太阳图像。
如您所见,客户端甚至不知道 dummyweatherforecast.com 和 SOAP 服务器之间进行了 SOAP 通信。这就是 SOAP 的使用方式:由服务器本身使用,很少直接由客户端使用。这就是我们所说的“Web 服务”,尽管这个术语指的是一组更通用的技术,用于让计算机相互通信。
我希望这能让你的头脑开朗一点。
PS:顺便说一句,您为服务器提供的链接指向一个不公开的 IP(192.168 地址用于专用网络)。
关于javascript - 如何发送 SOAP 请求并使用 HTML 接收响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28582872/