为什么是“wsdl"使用 savon 进行 ruby​​ soap 通信时,命名空间插入到动作名称中? [英] Why is "wsdl" namespace interjected into action name when using savon for ruby soap communication?

查看:13
本文介绍了为什么是“wsdl"使用 savon 进行 ruby​​ soap 通信时,命名空间插入到动作名称中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问我无法控制的 SOAP 服务.其中一项操作称为ProcessMessage.我按照示例生成了一个 SOAP 请求,但是我收到一条错误消息,指出该操作不存在.我将问题追溯到信封主体的生成方式.

I'm trying to access a SOAP service I don't control. One of the actions is called ProcessMessage. I followed the example and generated a SOAP request, but I got an error back saying that the action doesn't exist. I traced the problem to the way the body of the envelope is generated.

<env:Envelope ... ">
    <env:Header>
        <wsse:Security ... ">
            <wsse:UsernameToken ...">
                <wsse:Username>USER</wsse:Username>
                    <wsse:Nonce>658e702d5feff1777a6c741847239eb5d6d86e48</wsse:Nonce>
                    <wsu:Created>2010-02-18T02:05:25Z</wsu:Created>
                    <wsse:Password ... >password</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </env:Header>
    <env:Body>
        <wsdl:ProcessMessage>
            <payload>
                ......
            </payload>
        </wsdl:ProcessMessage>
    </env:Body>
</env:Envelope>     

那个 ProcessMessage 标签应该是:

    <ProcessMessage xmlns="http://www.starstandards.org/webservices/2005/10/transport">

当它由示例 Java 应用程序生成时就是这样,并且它可以工作.该标记是我的 Ruby 应用程序生成的内容与示例 Java 应用程序之间的唯一区别.有什么方法可以摆脱那个标签前面的 "wsdl:" 命名空间并添加这样的属性.除此之外,有没有办法强制动作不会像身体的其余部分一样作为字符串传递?

That's what it is when it is generated by the sample Java app, and it works. That tag is the only difference between what my Ruby app generates and the sample Java app. Is there any way to get rid of the "wsdl:" namespace in front of that one tag and add an attribute like that. Barring that, is there a way to force the action to be not to be generated by just passed as a string like the rest of the body?

这是我的代码:

require 'rubygems'
require 'savon'
client = Savon::Client.new "https://gmservices.pp.gm.com/ProcessMessage?wsdl"

response = client.process_message! do | soap, wsse |
wsse.username = "USER"
wsse.password = "password"
soap.namespace = "http://www.starstandards.org/webservices/2005/10/transport" #makes no difference
soap.action = "ProcessMessage" #makes no difference
soap.input = "ProcessMessage" #makes no difference

#my body at this point is jsut one big xml string

soap.body = "<payload>...</payload>" 
# putting <ProccessMessage> tag here doesn't help as it just creates a duplicate tag in the body, since Savon keeps interjecting  <wsdl:ProcessMessage> tag.

  end

我尝试过 handsoap 但它不支持 HTTPS 并且令人困惑.我尝试过soap4r,但它比handsoap 更令人困惑.

I tried handsoap but it doesn't support HTTPS and is confusing. I tried soap4r but but it's even more confusing than handsoap.

推荐答案

Steve,你看到 ProcessMessage 标签前面的 wsdl: 了吗?- 我认为这是唯一让我失望的事情,但事实并非如此(顺便说一下,它很难在第 160 行的 Savon lib 中的soap.rb 中设置).即使我没有在soap.namespaces 中对它进行spacify - 它也很难生成并附加到最​​终的xml 中.这是我的服务不允许的.

Steve, you see that wsdl: in front of ProcessMessage tag? - I thought that was the only thing that was throwing me off but its not ( by the way it's hard set in soap.rb in Savon lib on line 160). That even if I don't spacify it in soap.namespaces - it's hard generated and attached in final xml. Which is not allowed by my service.

虽然生成的 xml 是有效的 xml - 根据我试图与之交谈的服务的要求,它并不完整.即:在生成的 xml 中,

While the xml that is generated is a valid xml - it's not complete by the requirments of the service I'm trying to talk to. I.e.: in generated xml,

<?xml version="1.0" encoding="UTF-8"?>

标签丢失,此外,我需要在标题中使用 PayloadManifest,另外我需要 wsu:created 和 wsu:expires 在我的 wsse: 标签中,但它们没有实现,等等等等.还有一堆其他的小怪癖对我的情况太具体了.但是,soap 有一个私有方法 = xml_body.to_xml 方法中的soap lib 也在生成它自己的xml 之前检查@xml_body 是否已经设置.所以我最终稍微修改了肥皂的行为.通过使 soap.xml_body = 可公开访问.所以我能够做到:

tag is missing, also, I need PayloadManifest in the header,plus I need wsu:created and wsu:expires in my wsse: tag, but they are not implemented, etc., etc. a bunch of other little quirks that are too specific to my case. However soap has a private method = xml_body. Also soap lib in to_xml method is checking whether @xml_body was already set, before generating it's own xml. So I ended up slighly modifying behavior of soap. by making soap.xml_body = publicly accessable. So I was able to do:

response = client.process_message! do |soap| 
soap.action = "http://www.starstandards.org/webservices/2005/10/transport/operations/ProcessMessage"
soap.xml_body = "MY XML STRING GENERATED ELSEWHERE GOES HERE"
end

终于成功了!!!!

我会向 rubii 推荐这个 - 如果这个选项可用,可以解决很多罕见的情况 - 人们可以生成他们的自定义 xml 并使用 savon lib 的其余部分.

I'll suggest this to rubii - if this option becomes available that will solve a lot rare cases - where people can generate their custom xml and use the rest of savon lib.

这篇关于为什么是“wsdl"使用 savon 进行 ruby​​ soap 通信时,命名空间插入到动作名称中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆