0

我正在尝试使用以下代码配置我的 rails 应用程序以与肥皂网络服务通信:

client = Savon::Client.new do
  wsdl.document = "http://services.carsolize.com/BookingServices/dynamicdataservice.svc?wsdl"
end

response = client.request "ServiceRequest", "xmlns" => "http://tempuri.org/" do |soap, wsdl|
  client.http.headers["SOAPAction"] = '"http://tempuri.org/IDynamicDataService/ServiceRequest"'
  soap.body = {
    "rqst" => {
      "Credentials" => {
        "UserName" => 'user',
        "Password"  => 'pass'
      },
      "RequestType" => "Login", 
      "TypeOfService" => "Unknown",
    },
  }
end

但我得到的只是 HomeController#index 中的 Savon::HTTP::Error (并且没有更多信息),用于以响应开头的行。

4

2 回答 2

0

我试过这样做

client = Savon.client 'http://services.carsolize.com/BookingServices/dynamicdataservice.svc?wsdl'

username = '*********'
password = '*********'

response = client.request :wsdl, :login do
  http.headers["SOAPAction"] = '"http://tempuri.org/IDynamicDataService/ServiceRequest"'
  soap.xml = "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><ServiceRequest xmlns='http://tempuri.org/'><rqst xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><Credentials xmlns=''>
  <Password>#{password}</Password><UserName>#{username}</UserName></Credentials><RequestType xmlns=''>Login</RequestType><TypeOfService xmlns=''>Unknown</TypeOfService></rqst></ServiceRequest></s:Body></s:Envelope>"
end

它工作正常

于 2013-02-15T10:07:00.020 回答
0

我遇到了同样的错误,尽管它没有及时回答,但将来可能会发布它,这可能对某人有所帮助。

使用 Savon 实现 OAuth2.0

我们需要将内容类型"Content-Type" => "text/xml" 与承载令牌一起放入请求标头中

  client = Savon.client(
     wsdl: [URL],
     logger: Rails.logger,
     log_level: :debug,
     log: true,
     ssl_ca_cert_file: file_path,
     ssl_verify_mode: :none,
     headers: { "Authorization" => "Bearer #{auth_token}", "Content-Type" => "text/xml" },
     follow_redirects: true
  )
于 2021-12-01T07:32:05.957 回答