使用wsdl2java和Apache CXF的SOAP客户端

时间:2016-06-10 18:33:00

标签: java soap apache-camel cxf

我使用Apache CXF codegen插件运行wsdl2java命令。摘自我的WSDL:

<!-- submitSMSv3 -->
  <message name="submitSMSv3">
    <part name="parameters" element="tns:submitSMSv3"></part>
    <!--<part name="gdspHeader" element="tns:gdspHeader"></part>-->
  </message>
  <message name="submitSMSv3Response">
    <part name="result" element="tns:submitSMSv3Response"></part>
  </message>
  <portType name="SMSv3">
    <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
      <jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
    </jaxws:bindings>
    <operation name="SubmitSMSv3" parameterOrder="parameters">
      <input message="tns:submitSMSv3"></input>
      <output message="tns:submitSMSv3Response"></output>
    </operation>
  </portType>
  <binding name="SubmitSMSv3PortBinding" type="tns:SMSv3">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
    <operation name="SubmitSMSv3">
      <soap:operation soapAction=""></soap:operation>
      <input>
        <soap:body use="literal" parts="parameters"></soap:body>
        <!--<soap:header message="tns:submitSMSv3" part="gdspHeader" use="literal"></soap:header>-->
      </input>
      <output>
        <soap:body use="literal"></soap:body>
      </output>
    </operation>
  </binding>
  <service name="SubmitSMSv3Service">
    <port name="SubmitSMSv3Port" binding="tns:SubmitSMSv3PortBinding">
      <soap:address location="http://localhost:${HttpDefaultPort}/GDSPWebServices/SMSv3Service"></soap:address>
    </port>
  </service>

当我调用服务时,我的SOAP主体看起来像这样:

<soap:Body>
    <ns1:submitSMSv3 xmlns:ns1="http://ws.gdsp.vodafone.com/">
        <ns2:arg0 xmlns:ns2="http://ws.gdsp.vodafone.com/">
            <deviceId>xxxxxx</deviceId>
            <messageData></messageData>
            <messageType>Text</messageType>
        </ns2:arg0>
    </ns1:submitSMSv3>
</soap:Body>

但是我不想要代码,因为它没有通过网络电话,我希望我的肥皂体看起来像这样:

 <soap:Body>
        <ns1:submitSMSv3 xmlns:ns1="http://ws.gdsp.vodafone.com/">
                <deviceId>xxxxxxx</deviceId>
                <messageData></messageData>
                <messageType>Text</messageType>
        </ns1:submitSMSv3>
    </soap:Body>

我不知道该做什么才能让它成为这样,因为我知道这种方式有效。

1 个答案:

答案 0 :(得分:0)

在POJO消息传递格式的许多困难之后,我选择使用PAYLOAD,现在一切都按设计工作。我不得不为请求和响应添加处理器,但它现在可以工作了。