我正在尝试访问我无法控制的SOAP服务.其中一个操作称为ProcessMessage.我按照示例生成了一个SOAP请求,但是我收到一条错误,说该操作不存在.我将问题追溯到信封体生成的方式.
<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:”命名空间并添加这样的属性.除此之外,有没有办法强制动作不是通过像身体其他部分一样传递出来的?
这是我的代码:
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更令人困惑.
解决方法
您需要将数组传递给soap.input,其中第二个元素是包含命名空间详细信息的哈希.
soap.input = [ "ProcessMessage",{"xmlns" => "http://www.starstandards.org/webservices/2005/10/transport"} ]
您可能也会在元素之前结束命名空间声明
<env:Body> <wsdl:ProcessMessage xmlns="........." > <payload> ...... </payload> </wsdl:ProcessMessage> </env:Body>