Java SOAP WebService - 如何接受单个输入参数

时间:2017-03-31 19:45:22

标签: java web-services soap wsdl soapui

我正在开发一个基于SOAP的Web服务API,它将由第三方系统使用。 WSDL文件和端点URL将与它们共享,并通过传递输入参数并获取响应来调用我的Web服务

到目前为止,我已经创建了Web服务API,包括WSDL,服务类,帮助程序类,DAO,Ibatis),并通过传递输入参数使用SOAP UI进行测试,请求命中数据库并返回响应。附加了WSDL文件和SOAP请求和响应。

我有两个问题,

  1. 第三方系统要求提供API文档和SOAP信封。我该怎么办?

  2. 第三方系统必须通过传递输入参数sQuoteRef来调用我的服务。他们通常会怎么做?我并不关心这里的客户端代码,但是第三方的请求会是什么样子以及我应该在WSDL或Java类中进行哪些更改以接收输入参数并传递给我的服务类?

    < / LI>

    任何输入都有助于完成我的任务。非常感谢!

    WSDL文件

        <?xml version="1.0" encoding="UTF-8"?><wsdl:definitions name="EmpService" targetNamespace="http://emp.provider.integration.gi.sample.ie/EmpService/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://Emp.provider.integration.gi.sample.ie/EmpService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <wsdl:types>
            <xsd:schema targetNamespace="http://Emp.provider.integration.gi.sample.ie/EmpService/">
    
              <xsd:element name="EmpRequestVO">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element maxOccurs="1" minOccurs="1" name="sQuoteRef" type="xsd:string"/>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="EmpResponseVO">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element maxOccurs="1" minOccurs="0" name="sQuoteStatus" type="xsd:string"/>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:schema>
          </wsdl:types>
    
          <wsdl:message name="GetEmpTransactionSoapIn">
            <wsdl:part element="tns:EmpRequestVO" name="parameters"/>
          </wsdl:message>
          <wsdl:message name="GetEmpTransactionSoapOut">
            <wsdl:part element="tns:EmpResponseVO" name="parameters"/>
          </wsdl:message>
    
          <wsdl:portType name="EmpServiceSoap">
            <wsdl:operation name="getEmpTransaction">
              <wsdl:input message="tns:GetEmpTransactionSoapIn"/>
              <wsdl:output message="tns:GetEmpTransactionSoapOut"/>
            </wsdl:operation>
          </wsdl:portType>
    
          <wsdl:binding name="EmpServiceSoap" type="tns:EmpServiceSoap">
            <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="getEmpTransaction">
              <soap:operation soapAction="getEmpTransaction" style="document"/>
              <wsdl:input>
                <soap:body use="literal"/>
              </wsdl:input>
              <wsdl:output>
                <soap:body use="literal"/>
              </wsdl:output>
            </wsdl:operation>
          </wsdl:binding>
    
          <wsdl:service name="PLUSEmpServices">
            <wsdl:port binding="tns:EmpServiceSoap" name="EmpServiceSOAP">
              <soap:address location="http://localhost:9080/WebServices/services/EmpServiceSOAP"/>
            </wsdl:port>
          </wsdl:service>
        </wsdl:definitions>
    

    终点网址 http://localhost:9080/PLUSEmpServices/services/EmpServiceSOAP

    SOAP REQUEST in SOAP UI
    
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtw="http://emp.provider.integration.gi.sample.ie/EmpService/">
       <soapenv:Header/>
       <soapenv:Body>
          <rtw:EmpRequestVO>
             <sQuoteRef>12123118</sQuoteRef>
          </rtw:EmpRequestVO>
       </soapenv:Body>
    </soapenv:Envelope>
    
    SOAP RESPONSE in SOAP UI
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Header/>
       <soapenv:Body>
          <p900:EmpResponseVO xmlns:p900="http://emp.provider.integration.gi.sample.ie/EmpService/">
             <sQuoteStatus>Active</sQuoteStatus>
          </p900:EmpResponseVO>
       </soapenv:Body>
    </soapenv:Envelope>
    

1 个答案:

答案 0 :(得分:0)

  

第三方系统要求提供API文档和SOAP信封。我该怎么办?

要启动与外部各方的API集成,您的客户需要一个技术API文档,该文档将成为完整API集成的参考,并为团队之间的任何技术交流提供基础。技术文件可能包括以下细节:

  1. 不同可用网络服务API及其要求的简要说明。

  2. API通信流程。如果客户端需要按特定顺序调用多个服务,这将非常有用。包括流程图将是解释系统流程的可能选项。

  3. 测试环境详细信息,如WSDL URL和访问凭据,如用户名,密码,代理代码等。

  4. 向服务器发送有效请求所需的所有字段的详细说明。字段详细信息可能包括以下内容:

    一个。提起姓名。

    湾描述

    ℃。数据类型。

    d。最大长度。

    即强制性,可选性或条件性。

    F。可能的值(如果有)。

  5. 所有可能的响应代码很长,其描述由服务器API发送到客户端API,指示事务处理的成功或失败。例如(0000表示成功,E001表示验证错误,E002系统错误,9999未知错误等)。

  6. 注意:响应代码应涵盖各种拒绝情况。

    1. 安全部分,解释如何在客户端和服务器应用程序之间安全地交换数据。

      一个。如果有的话,为部分或全部请求数据提及额外的加密机制。

      湾与客户端的通信类型是通过VPN或公共访问 通过https URL。请注意,您在问题中提到的网址已部署在本地计算机中,并且无法公开提供。

    2. 所有可用API网络方法的示例SOAP请求和响应xml格式。

    3. 提及API连接的任何其他规则或约束。

    4.   

      第三方系统必须通过传递输入参数sQuoteRef来调用我的服务。他们通常会怎么做?我不关心这里的客户端代码,但是第三方的请求会是什么样子以及我应该在WSDL或Java类中做出哪些更改来接收输入参数并传递给我的服务类?

      如果我理解正确,您会问我应该如何更改WSDL或Java类以正确接受客户端请求?通常服务器端API具有XML格式的优势需要交换,在您的情况下,它应该在WSDL中提及。因此,客户端将根据服务器WSDL URL中提到的定义创建有效请求。

      进一步阅读我对如何从Java类生成WSDL很有用:

      Eclipse WSDL generator (from java class)?

      SOAP fault handling in java

相关问题