【问题标题】:ruby-savon communicate with mono-wcfruby-savon 与 mono-wcf 通信
【发布时间】:2012-12-21 09:12:11
【问题描述】:

我是 mono wcf 的新手,我遇到了一些关于我的代码的问题。 最近,我使用 ruby​​-savon 从单声道的 wcf 主机获取数据。

这是我的红宝石代码:

client = Savon::Client.new do 
wsdl.document="http://localhost:9000/MonoWcf/MonoSevice/wsdl" 
end
puts client.wsdl.soap_actions
response = client.request  :get_data

这就是:

ruby -KU -- '/home/charlot/Documents/Aptana Studio 3 Workspace/rubyfun/soap/savon.rb'
W, [2012-12-21T02:45:41.845966 #10527]  WARN -- : HTTPI executes HTTP GET using the httpclient adapter
get_data
get_data_using_data_contract
D, [2012-12-21T02:45:41.856091 #10527] DEBUG -- : SOAP request: http://localhost:9000/MonoWcf/MonoSevice/soap
D, [2012-12-21T02:45:41.856294 #10527] DEBUG -- : SOAPAction: "http://localhost:9000/IMonoService/GetData", Content-Type: text/xml;charset=UTF-8, Content-Length: 293
D, [2012-12-21T02:45:41.856329 #10527] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
        <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://tempuri.org/"   xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body><GetData>
</GetData>
</env:Body>
</env:Envelope>
W, [2012-12-21T02:45:41.856403 #10527]  WARN -- : HTTPI executes HTTP POST using the httpclient adapter
D, [2012-12-21T02:45:41.873963 #10527] DEBUG -- : SOAP response (status 415):
D, [2012-12-21T02:45:41.874057 #10527] DEBUG -- : 
/usr/local/lib/ruby/gems/1.9.1/gems/savon-1.2.0/lib/savon/soap/response.rb:108:in `raise_errors': Savon::HTTP::Error
    from /usr/local/lib/ruby/gems/1.9.1/gems/savon-1.2.0/lib/savon/soap/response.rb:18:in `initialize'
    from /usr/local/lib/ruby/gems/1.9.1/gems/savon-1.2.0/lib/savon/soap/request.rb:35:in `new'
    from /usr/local/lib/ruby/gems/1.9.1/gems/savon-1.2.0/lib/savon/soap/request.rb:35:in `response'
    from /usr/local/lib/ruby/gems/1.9.1/gems/savon-1.2.0/lib/savon/client.rb:86:in `request'
    from /home/charlot/Documents/Aptana Studio 3 Workspace/rubyfun/soap/savon.rb:15:in `dosoap'
    from /home/charlot/Documents/Aptana Studio 3 Workspace/rubyfun/soap/savon.rb:23:in `<main>'

**

这是 mono-wcf wsdl:

** `

<import location="http://localhost:9000/MonoWcf/MonoSevice/wsdl?wsdl=wsdl0" namespace="http://localhost:9000"/>
<types/>
<binding name="BasicHttpBinding_IMonoService" type="i0:IMonoService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="GetData">
        <soap:operation soapAction="http://localhost:9000/IMonoService/GetData" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
    <operation name="GetDataUsingDataContract">
        <soap:operation soapAction="http://localhost:9000/IMonoService/GetDataUsingDataContract" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
</binding>
<service name="service">
    <port name="BasicHttpBinding_IMonoService" binding="tns:BasicHttpBinding_IMonoService">
        <soap:address location="http://localhost:9000/MonoWcf/MonoSevice/soap"/>
    </port>
</service>

` **但是当我在 windows(7) 中托管 wcf 时,它确实可以获取数据。

我的操作系统是:ubuntu 12 单声道版本:

Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS:           __thread
SIGSEGV:       altstack
Notifications: epoll
Architecture:  x86
Disabled:      none
Misc:          softdebug 
LLVM:          supported, not enabled.
GC:            Included Boehm (with typed GC and Parallel Mark)

非常感谢您的帮助!

【问题讨论】:

  • 不是一个答案,但在这些情况下,使用 Wireshark 来准确了解网络上发生了什么通常是一个好的开始。
  • @troelskn 谢谢你,我会试试你的想法:)
  • 我在 tcpdump 中看到的错误消息是 'HTTP/1.1 415 Expected content-type 'text/xml; charset=utf-8' 但得到 'text/xml;charset=UTF-8'
  • 所以这是 Mono 的 WCF 堆栈中的一个错误。应该很容易解决,我去看看。
  • @MartinBaulig 谢谢,你真的帮了我:)

标签: ruby wcf mono savon


【解决方案1】:

这是我刚刚在 mono/master commit ea2f2cd 中修复的 Mono 的 WCF 代码中的一个错误。

Ruby-savon 发送Content-Type: text/xml;charset=UTF-8,但服务器需要Content-Type: text/xml; charset=utf-8。这是不正确的,检查应该不区分大小写并忽略空格。

您需要从 github 编译最新的单声道,或者作为临时解决方法,以某种方式让 ruby​​-savon 发送 Content-Type: text/xml; charset=utf-8

临时解决方法

编辑lib/savon/request.rb(在我的Mac上位于/Library/Ruby/Gems/1.8/gems/savon-2.0.2),在顶部,有

CONTENT_TYPE = {
  1 => "text/xml;charset=%s",
  2 => "application/soap+xml;charset=%s"
}

改成

CONTENT_TYPE = {
  1 => "text/xml; charset=%s",
  2 => "application/soap+xml; charset=%s"
}

然后将编码设置为“utf-8”,例如:

require 'savon'

client = Savon.client(:wsdl => "http://localhost:9999/MyService?wsdl", :encoding => "utf-8")
puts client.operations
response = client.call(:hello)

在我的 Mac 上使用 Ruby 1.8.7 进行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-22
    相关资源
    最近更新 更多