ruby-on-rails - 带有自定义绑定(bind)的 Savon

标签 ruby-on-rails ruby wcf soap savon

我有一个可爱的任务,就是使用 Rails 处理大量的 SOAP api。 SOAP 服务具有三种不同的绑定(bind); wsHttpBinding、wsHttpBinding with x509 和自定义绑定(bind)。我可以仅使用 wsHttpBinding 到达两个端点,但第三个端点需要用户名和密码,这不适用于此。由于证书的原因,我避免使用 x509,并且自定义绑定(bind)在 SoapUI 中工作得很好,但是对于 Savon,我得到以下错误。

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

我已经采用了用 Savon 生成的确切 XML 并将其放入 SoapUI 并且它可以工作。

这可能是一个有约束力的问题吗?有没有办法告诉它使用这个自定义绑定(bind)?

这是我在 App.config 中找到的自定义绑定(bind)

<bindings>
  <customBinding>
    <binding name="cust">
        <textMessageEncoding messageVersion="Soap12" />
        <httpTransport />
    </binding>
    <binding name="cust1">
        <textMessageEncoding messageVersion="Soap12" />
        <httpTransport />
    </binding>
    <binding name="cust2">
        <textMessageEncoding messageVersion="Soap12" />
        <httpTransport />
    </binding>
  </customBinding>
</bindings>
<endpoint address="http://api.xyz.com/stuff.svc/cust"
    binding="customBinding" bindingConfiguration="cust" contract="stuff.Xstuff"
    name="cust" />

编辑#1

这是我当前的客户端设置,以防有帮助。

@client = Savon.client(
      wsdl: 'http://api.xyz.com/stuff.svc?wsdl',
      wsse_auth: %w'username password',
      wsse_timestamp: true,
      raise_errors: false,
      log: true,
      log_level: :debug,
      soap_version: 2,
      pretty_print_xml: true,
      convert_request_keys_to: :none,
      use_wsa_headers: true,
      headers: {'Content-Type' => 'application/soap+xml; charset=utf-8'}

编辑 #2

我发现了问题。 Savon 没有像 SoapUI 那样在 Content-Type 中设置操作。感谢@RicardoPontual 建议尝试再次比较 Savon 和 SoapUI 请求,这让我仔细观察并注意到了问题。

headers: {'Content-Type' => 'application/soap+xml;charset=UTF-8;action="tempuri.org/stuf‌​f/set_table_stuff"'} 

最佳答案

您需要在 Content-Type header 中设置 action="tempuri.org/stuf‌ f/set_table_stuff"',如下所示:

@client = Savon.client(
      wsdl: 'http://api.xyz.com/stuff.svc?wsdl',
      wsse_auth: %w'username password',
      wsse_timestamp: true,
      raise_errors: false,
      log: true,
      log_level: :debug,
      soap_version: 2,
      pretty_print_xml: true,
      convert_request_keys_to: :none,
      use_wsa_headers: true,
      headers: {'Content-Type' => 'application/soap+xml; charset=UTF-8; action="tempuri.org/stuf‌​f/set_table_stuff";'}

关于ruby-on-rails - 带有自定义绑定(bind)的 Savon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39155817/

相关文章:

ruby-on-rails - ruby 中的整型变量声明

ruby-on-rails - 在多个具有相同最大值的情况下获取最大值作为数组

ruby-on-rails - rails 路线 : define root to namespace

css - sass 驱动版本的 Bootstrap 的简单最小化版本中哪个版本的 Bootstrap 更适合在 Rails 应用程序中使用

ruby-on-rails - 主要 :Object 的 RSpec 3.1 未定义方法 `feature'

wcf - .NET 中的 HTTPS Web 服务问题

.net - 在 SvcUtil 和 WSDL 代码生成期间抓取 KnownType 属性

ruby-on-rails - 更改默认 Rails text_area 辅助行/列

c# - 前缀 'xg0' 未定义

ruby-on-rails - 友好 ID 4 使用作用域模块