gpt4 book ai didi

java - SoapUI MockServices 返回 html 而不是 xml 响应

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:37:36 25 4
gpt4 key购买 nike

使用以下示例 WSDL 文件,我在 SOAP UI(版本 3.5)中生成了一个新项目,并创建了示例测试套件、测试用例和模拟服务。

WSDL

<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>

<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>

<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>

<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://www.examples.com/SayHello/"/>
</port>
</service>
</definitions>

我可以启动模拟服务并通过浏览器访问,由此我可以看到指向 wsdl 的链接并可以查看它。

但是,通过使用默认生成的 soap 请求(如下),它返回一个 html 响应(看起来是网页)而不是我配置的 soap 响应。

请求

POST http://localhost:8088/SayHello/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "sayHello"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:8088
Content-Length: 467

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:examples:helloservice">
<soapenv:Header/>
<soapenv:Body>
<urn:sayHello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<firstName xsi:type="xsd:string">James</firstName>
</urn:sayHello>
</soapenv:Body>
</soapenv:Envelope>

响应

HTTP/1.1 200 OK
Content-Type: text/html; charset=iso-8859-1
Transfer-Encoding: chunked
Server: Jetty(6.1.x)

<html><body><p>There are currently 1 running soapUI MockServices</p><ul><li><a href="/mockHello_Binding?WSDL">Hello_Binding MockService</a></li></ul></p></body></html>

我已经配置了一个示例响应,如下所示:

模拟样本响应

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:examples:helloservice">
<soapenv:Header/>
<soapenv:Body>
<urn:sayHelloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<greeting xsi:type="xsd:string">?</greeting>
</urn:sayHelloResponse>
</soapenv:Body>
</soapenv:Envelope>

它被配置为默认响应,所以我不知道为什么不返回它。

有什么建议吗?对任何帮助我取得进展的事情 +1。

谢谢

最佳答案

没有为您请求的端点 URL 启动服务:http://localhost:8088/SayHello/。正如服务响应中所报告的,唯一启动的服务位于 URL http://localhost:8088/mockHello_Binding。当请求一个不存在的服务时,SoapUI 返回 HTML 页面中所有已启动的模拟服务的列表。考虑修复端点地址以解决此问题。

关于java - SoapUI MockServices 返回 html 而不是 xml 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8825659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com