【问题标题】:SOAP Request and Response using the same Element not showing in SoapUI使用相同元素的 SOAP 请求和响应未在 SoapUI 中显示
【发布时间】:2014-01-16 10:03:38
【问题描述】:

当人们通常创建一个 SOAP 请求和响应元素时,它会以 __Request 和 __Response 结尾,当您导入 WSDL 时,SoapUI 会选择它。

<xs:element name="SampleRequest">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Testing" type="xs:string" />  
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="SampleResponse">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Testing" type="xs:string" />  
        </xs:sequence>
    </xs:complexType>
</xs:element>

我正忙于转换一段旧的 VB6 代码,而 DTD 的 SOAP 等效项将使用相同的元素进行请求和响应:

<xs:element name="Sample">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Testing" type="xs:string" />  
        </xs:sequence>
    </xs:complexType>
</xs:element>

我可以在 XSD 中设置什么,以便 SOAPUI 将 Sample 拾取为请求和响应吗?

【问题讨论】:

    标签: java soap soapui spring-ws


    【解决方案1】:

    当 SOAPUI 读取 WSDL 时,它使用 wsdl:message 元素中定义的元素(以及元素名称),该元素是从 wsdl:operation 元素引用的请求、响应和可选故障。您对 XSD 所做的任何事情都不会改变这一点。元素也不必以“请求”结尾才能被视为请求(响应相同)。

    【讨论】:

    • 我正在使用自动生成 WSDL 的 Spring-ws,这是否意味着我需要手动将 Sample 操作添加到 WSDL 以便 SOAPUI 来获取它?
    • 是否可以配置 Spring-WS 以包含其他 wsdl:operations?
    • 我使用过的每个 Web 服务器容器都会生成 WSDL——即使你给它一个 WSDL。 (将 cmets 放入 WSDL,然后部署,然后从容器中获取 WSDL - cmets 很可能会消失。)容器这样做是为了确保 WSDL 与部署的应用程序匹配,这可能是个好主意。
    • 我对 Spring-ws 一无所知,但我假设它支持 JSR 181 注释。如果您使用 @WebResult(name="SampleResponse") 注释您的方法并使用 @WebParam(name = "SampleRequest") 注释您的方法参数,那么您将获得所需的元素名称。
    • 我使用过滤器在 WSDL 显示之前对其进行拦截,然后将 SampleRequest 和 SampleResponse 字符串替换为 Sample ,效果非常好。
    【解决方案2】:

    通过将所有 SampleRequest 和 SampleResponse 替换为 Sample 并删除现在重复的 wsdl:message 来解决它:

    ...
    
    
    <wsdl:message name="Sample">
        <wsdl:part element="tns:Sample" name="Sample">
        </wsdl:part>
    </wsdl:message>
    
    <wsdl:portType name="SampleSoapService">
        <wsdl:operation name="Sample">
            <wsdl:input message="tns:Sample" name="Sample">
            </wsdl:input>
            <wsdl:output message="tns:Sample" name="Sample">
            </wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    
    <wsdl:binding name="SampleSoapServiceSoap11" type="tns:SampleSoapService">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="Sample">
            <soap:operation soapAction="" />
            <wsdl:input name="Sample">
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="Sample">
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="SampleSoapServiceService">
        <wsdl:port binding="tns:SampleSoapServiceSoap11" name="SampleSoapServiceSoap11">
            <soap:address location="http://localhost:8080/paygate-SampleSoapService/ws/SampleSoapService" />
        </wsdl:port>
    </wsdl:service>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多