为什么JAXWS在消息中生成名称空间?

时间:2017-02-28 16:38:19

标签: java xml namespaces wsdl jax-ws

我有一个从WSDL生成的类:

<?xml version="1.0" encoding="UTF-8"?>                                                                                                                            
<wsdl:definitions xmlns:p1="http://V2/B/ISP/Global" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/   oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="SI_Message_SYN_OUT" targetNamespace="http://V2/B/ISP/Global">
  <wsdl:documentation/>
  <wsp:UsingPolicy wsdl:required="true"/>
  <wsp:Policy wsu:Id="OP_SI_Message_SYN_OUT"/>
  <wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="my-message" type="myMessage"/>
      <xsd:complexType name="myMessage">
        <xsd:sequence>
          <xsd:element name="message-header" type="MessageHeader"/>
          <xsd:element name="message-content" type="MessageContent"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="MessageHeader">
        <xsd:annotation>
          <xsd:documentation>Message header</xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
          <xsd:element name="id" type="xsd:string" />
          <xsd:element name="timestamp" type="xsd:dateTime" />
          <xsd:element name="user" type="xsd:string" />
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="MessageContent">
        <xsd:choice>
          <xsd:element name="ping-message" type="PingMessage"/>
        </xsd:choice>
      </xsd:complexType>
      <xsd:complexType name="PingMessage"/>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="xmln.my-message">
    <wsdl:documentation/>
    <wsdl:part xmlns="" name="my-message" element="my-message"/>
  </wsdl:message>
  <wsdl:portType name="SI_Message_SYN_OUT">
    <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
    </jaxws:bindings>
    <wsdl:documentation/>
    <wsdl:operation name="SI_Message_SYN_OUT">
      <wsdl:documentation/>
      <wsp:Policy>
        <wsp:PolicyReference URI="#OP_SI_Message_SYN_OUT"/>
      </wsp:Policy>
      <wsdl:input message="p1:xmln.my-message"/>
      <wsdl:output message="p1:xmln.my-message"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="SI_Message_SYN_OUTBinding" type="p1:SI_Message_SYN_OUT">
    <soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="SI_Message_SYN_OUT">
      <soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://sap.com/xi/WebService/soap1.1"/>
      <wsdl:input>
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="SI_Message_SYN_OUTService">
    <wsdl:port name="HTTP_Port" binding="p1:SI_Message_SYN_OUTBinding">
      <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://127.0.0.1:8888/XISOAPAdapter/MessageServlet?senderParty=&amp;             senderService=SRV_ISP&amp;receiverParty=&amp;receiverService=&amp;interface=SI_Message_SYN_OUT&amp;interfaceNamespace=http%3A%2F%2FV2%2FB%2FISP%2FGlobal"/>
    </wsdl:port>
    <wsdl:port name="HTTPS_Port" binding="p1:SI_Message_SYN_OUTBinding">
      <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="https://127.0.0.1:9999/XISOAPAdapter/MessageServlet?senderParty=&amp;            senderService=SRV_ISP&amp;receiverParty=&amp;receiverService=&amp;interface=SI_Message_SYN_OUT&amp;interfaceNamespace=http%3A%2F%2FV2%2FB%2FISP%2FGlobal"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>                                            

WSDL就是这样:

<?xml version="1.0"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:my-message xmlns:ns2="http://V2/B/ISP/Global">
      <message-header>
        <id>9f45a507-3f56-4a30-aefe-28368282bcbe</id>
        <timestamp>2015-10-16T16:31:27</timestamp>
        <user>BFR</user>
      </message-header>
      <message-content>
        <ping-message/>
      </message-content>
    </ns2:my-message>                                                                                                                                             
  </S:Body>
</S:Envelope>

通过此Web服务发送消息时,实际发送的XML如下所示:

xmlns:ns2="http://V2/B/ISP/Global"

服务器拒绝此消息,似乎问题是my-message标记上的附加命名空间:my-message。 这应该显然不存在。

现在,我的问题是:这个名称空间应该存在吗?当我查看由JAX-WS生成的webservice接口时,它会看到template<typename T> static const std::string numberToString(T number) { char res[25]; // next line is a bit pseduo-y snprintf(res, sizeof(res), "%T", number); return string(res); } 的targetNamespace为空。那么,XML中的my-message标签也不应该没有命名空间吗?

0 个答案:

没有答案