简体   繁体   English

邮递员在 SOAP 响应中返回空值

[英]Postman Returning Null Values in SOAP Response

I am new to SOAP and POSTMAN and am wondering what I am doing wrong with the following.我是 SOAP 和 POSTMAN 的新手,想知道我在以下方面做错了什么。 I have a sample java webservice using jax-ws:我有一个使用 jax-ws 的示例 java webservice:

@WebService(endpointInterface = "Soap1.SOAPInterface")
public class SOAPService implements SOAPInterface
{
public String message(String name)
{
    return "Hello " + name;
}
}

I published this webservice using an Endpoint:我使用端点发布了这个网络服务:

public class Publisher 
{
public static void main(String[]args)
{
    Endpoint.publish("http://localhost:9006/Service", new SOAPService());
}
}

Now when I run this in a client it works fine现在当我在客户端运行它时它工作正常

    public static void main(String[] args) throws Exception
    {
    URL url = new URL("http://localhost:9006/Service?wsdl");
    QName qname = new QName("http://Soap1/","SOAPServiceService");
    Service s = Service.create(url,qname);
    SOAPInterface i = s.getPort(SOAPInterface.class);
    System.out.println(i.message("Bob"));
    }

However when trying to use POSTMAN to analyze SOAP request/responses.但是,当尝试使用 POSTMAN 分析 SOAP 请求/响应时。 By entering the following xml for a request:通过为请求输入以下 xml:

 <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <MyMessage xmlns="http://Soap1/"> <name>Bob</name> </MyMessage> </Body> </Envelope>

I get a response of Hello null我收到 Hello null 的响应

 <?xml version="1.0" ?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:MyMessageResponse xmlns:ns2="http://Soap1/"> <returnedMessage>Hello null</returnedMessage> </ns2:MyMessageResponse> </S:Body> </S:Envelope>

I am wondering why this is because using the client, the parameters are passing fine but when using POSTMAN they seem not to be passing.我想知道为什么这是因为使用客户端,参数传递得很好,但是当使用 POSTMAN 时,它们似乎没有传递。

Screenshot of postman:邮递员截图: 邮差

If you open in browser URI http://localhost:9006/Service?wsdl , you'll see WSDL generated by JAX-WS for your service.如果您在浏览器 URI 中打开http://localhost:9006/Service?wsdl ,您将看到 JAX-WS 为您的服务生成的 WSDL。 It should contain following snippet:它应该包含以下代码段:

<types>
<xsd:schema>
<xsd:import namespace="http://example.soap.kdv.org/" schemaLocation="http://localhost:9006/Service?xsd=1"/>
</xsd:schema>
</types>

It contains reference to XML schema defining structure of XML messages used in web-service.它包含对定义 Web 服务中使用的 XML 消息结构的 XML 模式的引用。 If you open URI http://localhost:9006/Service?xsd=1 as well (URI can differ, please check it), you'll see definition of request and response message:如果您也打开 URI http://localhost:9006/Service?xsd=1 (URI 可能不同,请检查它),您将看到请求和响应消息的定义:

<xs:schema xmlns:tns="http://example.soap.kdv.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://example.soap.kdv.org/">
<xs:element name="message" type="tns:message"/>
<xs:element name="messageResponse" type="tns:messageResponse"/>
<xs:complexType name="message">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="messageResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

It defines following structure of request message:它定义了以下请求消息的结构:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://example.soap.kdv.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <exam:message>
         <!--Optional:-->
         <arg0>test</arg0>
      </exam:message>
   </soapenv:Body>
</soapenv:Envelope>

Try this message in postman, it should return you desired result.在邮递员中尝试此消息,它应该会返回您想要的结果。

Also I'd like to recommend SOAP UI tool for testing web services.另外,我想推荐用于测试 Web 服务的 SOAP UI 工具。 When creating new SOAP project in this tool, it imports WSDLs and generates for you request messages.在此工具中创建新的 SOAP 项目时,它会导入 WSDL 并为您生成请求消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM