3

我在 Visual Studio 中使用“添加服务引用”选项,以便使用第三方提供给我的 WSDL 文件创建代理类。我得到了 WSDL 的 2 个版本——我们称它们为“OLD”和“NEW”。

即使 WSDL 文件假设是相同的(新的有更新的方法版本),在创建代理类时,我在 OperationContractAttribute.Action 中得到不同的值。

在 OLD wsdl 中,它看起来像这样:

[System.ServiceModel.OperationContractAttribute(Action="http://webservices.amadeus.com/SATRQT_13_2_1A", ReplyAction="*")]

在新的 wsdl 中,它看起来像这样:

[System.ServiceModel.OperationContractAttribute(Action="http://xml.amadeus.com/AmadeusWebServicesPT/Air_MultiAvailabilityRequest", ReplyAction="http://xml.amadeus.com/AmadeusWebServicesPT/Air_MultiAvailabilityResponse")]

我无法弄清楚“Action”值的来源。

在旧的 WSDL 中,该值是有效的,但在新的 WSDL 中是完全错误的,并且在尝试使用 WS 中的服务时出现异常

当我查看 OLD wsdl 文件时,我可以看到具有相同值的“soapAction”;这似乎是它的来源。然而,在 NEW wsdl 中有一个与 OLD wsdl 完全相同的值

<wsdl:operation name="Air_MultiAvailability">
  <soap:operation soapAction="http://webservices.amadeus.com/SATRQT_13_2_1A" />

任何人都可以指导我到正确的地方吗?

更新

在阅读了有关“操作”元素的更多内容后,我意识到我在 NEW wsdl 中看到的值是默认值(请参阅https://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute。动作(v=vs.110).aspx

现在我需要了解为什么在 OLD wsdl 文件中我们得到的 Action 值是正确的(我从正确操作下的 wsdl 文件中定义的soapAction猜测)并且在 NEW wsdl 中没有匹配项和一个填充默认值?

4

1 回答 1

3

好的 找到问题了!

在 WSDL 文件中有多个同名的“操作”

<wsdl:portType name="WebServices"> 
  <wsdl:operation name="DoSomething">
      <wsdl:input message="ns:DoSomething_1_1" />
      <wsdl:output message="ns:DoSomething_1_1" />
    </wsdl:operation>
    <wsdl:operation name="DoSomething">
      <wsdl:input message="ns:DoSomething_2_2" />
      <wsdl:output message="ns:DoSomething_2_2" />
    </wsdl:operation>
  </wsdl:portType>

<wsdl:binding type="ns:WebServices" name="WebServicesBinding">
    <wsdl:operation name="DoSomething">
      <soap:operation soapAction="http://webservices.my.com/DoSomething_1_1" />
    </wsdl:operation>
    <wsdl:operation name="DoSomething">
      <soap:operation soapAction="http://webservices.my.com/DoSomething_2_2" />
    </wsdl:operation>
</wsdl:binding>

一旦我删除\重命名所有重复的操作(我有多个),“DoSomething”在此示例中获得了 2 个版本 1.1 和 2.2,“Action”值取自“soapAction”元素

希望这对将来的人有所帮助!

于 2018-05-16T08:02:58.967 回答