【问题标题】:Java SOAP WebService - How to accept single input parameterJava SOAP WebService - 如何接受单个输入参数
【发布时间】:2017-03-31 19:45:22
【问题描述】:

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

到目前为止,我已经创建了 Web Service API,包括 WSDL、Services Classes、Helper Classes、DAO、Ibatis)并通过传递输入参数使用 SOAP UI 进行了测试,请求命中数据库并返回响应正常。附加 WSDL 文件和 SOAP 请求和响应。

我有两个问题,

  1. 第 3 方系统要求提供 API 文档和 SOAP 信封。我应该给什么?

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

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

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>

【问题讨论】:

    标签: java web-services soap wsdl soapui


    【解决方案1】:

    第 3 方系统要求提供 API 文档和 SOAP 信封。我应该给什么?

    要开始与外部方进行 API 集成,您的客户需要一份技术 API 文档,该文档将作为完整 API 集成的参考以及团队之间任何技术交流的基础。技术文件可能包括以下细节:

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

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

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

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

      一个。文件名。

      b.说明。

      c。数据类型。

      d。最大长度。

      e。强制、可选或有条件的。

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

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

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

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

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

      b.与客户端的通信类型是通过 VPN 或访问公共 通过 https URL。请注意,您在问题中提到的 URL 已部署在您的本地计算机中,不会公开提供。

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

    3. 提及有关 API 连接的任何其他规则或限制。

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

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

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

    Eclipse WSDL generator (from java class)?

    SOAP fault handling in java

    【讨论】:

    • 嗨,Salman,感谢您抽出宝贵时间回答我的问题。您的答案在 API 文档方面非常清楚。现在我的问题是,我拥有的 WSDL 文件接受来自 SOAP UI 的请求并按预期返回响应。客户请求会是什么样子?可能是查询字符串?如果是这样,我应该对 WSDL 或 Java 类进行哪些更改以接受客户端请求以及输入参数并传回响应。
    • @user2381118 您正在构建服务器端 API,并使用 WSDL 将其公开给其他客户端。 WSDL 定义了来自客户端的请求的外观以及您使用 SoapUI 的体验。当您使用 SoapUI 时,您将它用作您构建的服务器 API 的客户端,SoapUI 基于给定的 WSDL 构建 XML 请求。同样,任何其他客户端都需要使用 WSDL 来格式化他们的请求。您不需要更改您的 WSDL 来接受不同的客户端请求,实际上它是另一种方式;客户端需要确保构建他们的请求与 WSDL 匹配
    • 谢谢萨尔曼。所以我想我不必担心,并且必须要求客户端系统构建他们的请求以匹配 WSDL。
    • 只是想知道,你知道如何实现 WS 安全吗?我必须使用用户名/密码验证客户端以确认其真实性。提前致谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2020-07-15
    • 2016-01-01
    相关资源
    最近更新 更多