无法在 Ruby on Rails 中通过 SOAP 连接 (SAVON) 调用 Web 服务方法。我哪里出错了?

发布于 2024-12-04 07:32:50 字数 2022 浏览 1 评论 0原文

我似乎收到此错误消息:

(a:ActionNotSupported) 操作为“GetServices”的消息不能 由于 ContractFilter 不匹配,在接收方进行处理 端点调度程序。这可能是由于合同不匹配 (发送者和接收者之间的操作不匹配)或绑定/安全 发送者和接收者之间的不匹配。检查发件人和 接收方具有相同的合同和相同的绑定(包括 安全要求,例如消息、传输、无)。

我认为这与安全/绑定设置有关。 我的连接使用 HTTP,带有 basichttpbinding。像往常一样,我做了很多寻找答案的工作,但无法修复它,而且这里没有人具备 Ruby on Rails 方面的专业知识。

如有帮助,将不胜感激。

下面是我在 Ruby on Rails 中的代码,它初始化服务然后调用它。注意:我可以正常连接。它已成功报告可用的方法。仅仅调用这些方法似乎就是问题所在。我已使用相同的代码成功连接到在线测试服务。我用萨翁。

  def test
    puts "web_service: IN"    
    client = Savon::Client.new do
      wsdl.document = "http://hidden.co.uk/myService.svc?wsdl"
    end

    @response = client.request "GetServices", :xmlns => "http://tempuri.org/" do
      soap.header = {}
      soap.body = {
        "CostCentreNo" => 1,
        "filter" => 0
      }
    end    
    puts '##########################'
    puts @response.to_hash;   
  end

以下是我的 Ruby on Rails 发送的内容:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:wsdl="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<GetServices xmlns="http://tempuri.org/">
<CostCentreNo>1</CostCentreNo>
<filter>0</filter>
</GetServices>
</env:Body>
</env:Envelope>

这是 WCF 测试客户端发送的内容(有效)

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IIBCSServices/GetServices</Action>
  </s:Header>
  <s:Body>
    <GetServices xmlns="http://tempuri.org/">
      <CostCentreNo>0</CostCentreNo>
      <filter>0</filter>
    </GetServices>
  </s:Body>
</s:Envelope>

I seem to be getting this error message:

(a:ActionNotSupported) The message with Action 'GetServices' 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).

I assume it is something to do with the security/binding setup.
My connection uses HTTP, with basichttpbinding. I've done a lot of searching for the answer, as I always do, but am unable to fix it, and no one here has expertise on Ruby on Rails.

Help would be appreciated.

Below is my code, in Ruby on Rails, which initialises the service and then calls it. Note: I can connect to it fine. It has successfully reported the available methods. Just calling the methods seems to be the problem. I have successfully connected to online test services using the same code. And I use Savon.

  def test
    puts "web_service: IN"    
    client = Savon::Client.new do
      wsdl.document = "http://hidden.co.uk/myService.svc?wsdl"
    end

    @response = client.request "GetServices", :xmlns => "http://tempuri.org/" do
      soap.header = {}
      soap.body = {
        "CostCentreNo" => 1,
        "filter" => 0
      }
    end    
    puts '##########################'
    puts @response.to_hash;   
  end

Below is what my Ruby on Rails sends:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:wsdl="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<GetServices xmlns="http://tempuri.org/">
<CostCentreNo>1</CostCentreNo>
<filter>0</filter>
</GetServices>
</env:Body>
</env:Envelope>

This is what WCF test client sends, (which works)

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IIBCSServices/GetServices</Action>
  </s:Header>
  <s:Body>
    <GetServices xmlns="http://tempuri.org/">
      <CostCentreNo>0</CostCentreNo>
      <filter>0</filter>
    </GetServices>
  </s:Body>
</s:Envelope>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╭ゆ眷念 2024-12-11 07:32:50

好像就是这么称呼的……就是这么简单。

如果您的驼峰式开头是大写,则建议使用 SAVON 教程中规定的覆盖,但不起作用。也许教程已经过时了。 (注意,在我的情况下需要:wsdl)

所以这不起作用:

response = client.request :wsdl, "GetCustomerCentreDetails"

将其更改为:

 response = client.request :wsdl, :get_customer_centre_details

那么显然我需要添加一个正文,以及标题等。

导致我困惑的假设:能够获得WSDL 并不意味着您已连接到 Web 服务。

It seems to be the way it was being called... Something so simple.

The override Stated on the SAVON Tutorial, recommended if you have an uppercase starting camelcase doesnt work. Maybe the tutorial is outdated. (Note, :wsdl IS required in my case)

So this was not working:

response = client.request :wsdl, "GetCustomerCentreDetails"

Changing it to:

 response = client.request :wsdl, :get_customer_centre_details

Then obviously I need a body added to it, and header etc.

The assumption that caused me confusion : Being able to get the WSDL does not mean you are connected to the webservice.

笑看君怀她人 2024-12-11 07:32:50

看来您缺少这部分,

<Action s:mustUnderstand="1" ...>

您应该在您的请求中插入类似以下内容

soap.header = {"Action" =>
                {'env:mustUnderstand' =>
                 'http://tempuri.org/IIBCSServices/GetServices',
                attributes! => { 'mustUnderstand' => "1", 'xmlns' => "..." }
              }

it seems you're missing this part

<Action s:mustUnderstand="1" ...>

you should insert something like the following into your request

soap.header = {"Action" =>
                {'env:mustUnderstand' =>
                 'http://tempuri.org/IIBCSServices/GetServices',
                attributes! => { 'mustUnderstand' => "1", 'xmlns' => "..." }
              }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文