SOAP请求适用于PHP,但不适用于Ruby(gem:Savon2)
我试图执行名为DoProduct的SOAP请求。此方法正在更新特定产品。我浏览了WSDL(http://api.istore.pl/#op.idp182160),发现我需要一个Product对象和会话密钥。SOAP请求适用于PHP,但不适用于Ruby(gem:Savon2)
一切与PHP完美的工作:
$product = $soap->__soapCall("getProduct", array("sessionId" => $key, "productId" => $id));
$result = $soap->__soapCall("doProduct", array("sessionId" => $key, "product" => $product));
我试图用Ruby同样的方法(先获得产品,然后将其发送回):
product = client.call(:get_product, message: {:session_id => session_key, :product_id => id})
response = @@client.call(:do_product, message: {:session_id => session_key, :product => product.hash[:envelope][:body][:get_product_response][:return]})
的Ruby版本无法正常工作。我收到错误一个参数没有被发送(当然该参数是存在的,从第一个响应我检查哈希):
HTTPI POST request to api.istore.pl (net_http)
SOAP response (status 500)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><S
OAP-ENV:Body><SOAP-ENV:Fault><faultcode>ERR_EMPTY_PRODUCT_TAX</faultcode><faults
tring></faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
Savon::SOAPFault: (ERR_EMPTY_PRODUCT_TAX)
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/response.rb:70:in `raise_soap_and_http_errors!'
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/response.rb:13:in `initialize'
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/operation.rb:52:in `new'
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/operation.rb:52:in `call'
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.1.0/lib/savon/client.rb:38:in `call'
from C:/Users/Arti/Documents/adgally/v1/app/models/istore.rb:45:in `update_product'
from (irb):60
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from F:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
@EDIT PHP响应(vardump):
object(stdClass)[2]
public 'Id' => int 18028717
public 'PropertiesIds' =>
array (size=0)
empty
public 'ImagesIds' =>
array (size=1)
0 => int 22573396
public 'Currency' =>
object(stdClass)[3]
public 'Id' => int 1
public 'Symbol' => string 'PLN' (length=3)
public 'Round' => boolean false
public 'Active' => boolean true
public 'Rate' => float 1
public 'Tax' =>
object(stdClass)[4]
public 'Id' => int 23
public 'Name' => string '23%' (length=3)
public 'Rate' => float 23
public 'Symbol' => string ' ' (length=1)
public 'Promotion' => boolean false
public 'Wholesale' => boolean false
public 'New' => boolean false
public 'DeliveryTimeLength' => int 0
public 'DeliveryTimeLengthPeriod' => string 'D' (length=1)
public 'Producer' => null
public 'PKWiU' => null
public 'Active' => boolean true
public 'Netto' => float 11.38
public 'Brutto' => float 14
public 'PromotionNetto' => float 0
public 'PromotionBrutto' => float 0
public 'WholesaleNetto' => float 0
public 'WholesaleBrutto' => float 0
public 'FirstPage' => int 0
public 'Sequence' => int 18028717
public 'Unit' =>
object(stdClass)[5]
public 'Id' => int 1
public 'Symbol' => string 'szt.' (length=4)
public 'PostSize' => string 'A' (length=1)
public 'SortProperty' => string 'N' (length=1)
public 'MainCategory' =>
object(stdClass)[6]
public 'Id' => int 34
public 'Name' => string 'Odzież, Obuwie, Dodatki' (length=24)
public 'Names' =>
array (size=1)
0 =>
object(stdClass)[7]
public 'Symbol' => string 'pl' (length=2)
public 'Name' => string 'Bluzka testowa 2' (length=16)
public 'Description' =>
array (size=1)
0 =>
object(stdClass)[8]
public 'Symbol' => string 'pl' (length=2)
public 'Description' => string 'asdsad' (length=6)
public 'HTMLDescription' =>
array (size=1)
0 =>
object(stdClass)[9]
public 'Symbol' => string 'pl' (length=2)
public 'Description' => string 'asdasdas' (length=8)
public 'MetaKeywords' =>
array (size=1)
0 =>
object(stdClass)[10]
public 'Symbol' => string 'pl' (length=2)
public 'Description' => string 'bluzka, jesień, fajna' (length=22)
public 'CategoriesIds' =>
array (size=1)
0 => int 1695922
public 'BindingProducts' =>
array (size=0)
empty
public 'Availability' => string 'A' (length=1)
public 'Quality' => string 'N' (length=1)
public 'Variants' =>
array (size=1)
0 =>
object(stdClass)[11]
public 'ShopProductPropertyValueIds' =>
array (size=0)
...
public 'Quantity' => float 1
public 'WarehouseId' => int 20666112
public 'Available' => boolean true
public 'Weight' => float 0
public 'Blocked' => boolean false
public 'HideExternalOpinions' => boolean false
public 'Width' => int 0
public 'Height' => int 0
public 'Deep' => int 0
public 'InpostEnabled' => boolean false
public 'Available' => boolean true
public 'Ean' => null
红宝石萨翁response.to_hash对象(抱歉格式,但我没有任何想法如何将它从控制台正确格式):http://pastie.org/7065887
Additionaly红宝石response.to_json(格式更好):
{
"get_product_response":{
"return":{
"id":"18028717",
"properties_ids":{
"@soap_enc:array_type":"xsd:int[0]",
"@xsi:type":"ns1:ArrayOfint"
},
"images_ids":{
"item":"22573396",
"@soap_enc:array_type":"xsd:int[1]",
"@xsi:type":"ns1:ArrayOfint"
},
"currency":{
"id":"1",
"symbol":"PLN",
"round":false,
"active":true,
"rate":"1",
"@xsi:type":"ns1:Currency"
},
"tax":{
"id":"23",
"name":"23%",
"rate":"23",
"@xsi:type":"ns1:Tax"
},
"symbol":{
"@xsi:type":"xsd:string"
},
"promotion":false,
"wholesale":false,
"new":false,
"delivery_time_length":"0",
"delivery_time_length_period":"D",
"producer":null,
"pk_wi_u":null,
"active":true,
"netto":"11.38",
"brutto":"14",
"promotion_netto":"0",
"promotion_brutto":"0",
"wholesale_netto":"0",
"wholesale_brutto":"0",
"first_page":"0",
"sequence":"18028717",
"unit":{
"id":"1",
"symbol":"szt.",
"@xsi:type":"ns1:Unit"
},
"post_size":"A",
"sort_property":"N",
"main_category":{
"id":"34",
"name":"Odzieu017c, Obuwie, Dodatki",
"@xsi:type":"ns1:MainCategory"
},
"names":{
"item":{
"symbol":"pl",
"name":"Bluzka testowa 2",
"@xsi:type":"ns1:TranslationName"
},
"@soap_enc:array_type":"ns1:TranslationName[1]",
"@xsi:type":"ns1:ArrayOfTranslationName"
},
"description":{
"item":{
"symbol":"pl",
"description":"asdsad",
"@xsi:type":"ns1:TranslationDescription"
},
"@soap_enc:array_type":"ns1:TranslationDescription[1]",
"@xsi:type":"ns1:ArrayOfTranslationDescription"
},
"html_description":{
"item":{
"symbol":"pl",
"description":"asdasdas",
"@xsi:type":"ns1:TranslationDescription"
},
"@soap_enc:array_type":"ns1:TranslationDescription[1]",
"@xsi:type":"ns1:ArrayOfTranslationDescription"
},
"meta_keywords":{
"item":{
"symbol":"pl",
"description":"bluzka, jesieu0144, fajna",
"@xsi:type":"ns1:TranslationDescription"
},
"@soap_enc:array_type":"ns1:TranslationDescription[1]",
"@xsi:type":"ns1:ArrayOfTranslationDescription"
},
"categories_ids":{
"item":"1695922",
"@soap_enc:array_type":"xsd:int[1]",
"@xsi:type":"ns1:ArrayOfint"
},
"binding_products":{
"@soap_enc:array_type":"xsd:int[0]",
"@xsi:type":"ns1:ArrayOfint"
},
"availability":"A",
"quality":"N",
"variants":{
"item":{
"shop_product_property_value_ids":{
"@soap_enc:array_type":"xsd:int[0]",
"@xsi:type":"ns1:ArrayOfint"
},
"quantity":"1",
"warehouse_id":"20666112",
"available":true,
"@xsi:type":"ns1:ProductVariant"
},
"@soap_enc:array_type":"ns1:ProductVariant[1]",
"@xsi:type":"ns1:ArrayOfProductVariant"
},
"weight":"0",
"blocked":false,
"hide_external_opinions":false,
"width":"0",
"height":"0",
"deep":"0",
"inpost_enabled":false,
"available":true,
"ean":null,
"@xsi:type":"ns1:Product"
}
}
}
有没有人可以给我任何提示?
根据SOAP响应,您实际上缺少SOAP服务期望的参数。
我注意到PHP版本只是发送整个产品对象,但在Ruby版本中,您正在挖掘响应哈希。
你可以在两个版本中检查'产品'并在此发布回应吗?
+1希望看到回复。 – chaseadamsio 2013-03-21 21:38:59
我已经添加了对我的问题的回复。我非常感谢你的帮助。 – Arti 2013-03-22 12:06:27
它与错误ERR_EMPTY_PRODUCT_TAX无关? – Gerep 2013-03-21 20:02:45
调试?在控制器方法中像'raise params.inspect'这样的东西应该会返回你在soap响应中的请求参数 – ted 2013-03-21 20:04:14
对不起,但只是采用这个哈希并重用它可能不起作用。 – rubiii 2013-03-21 22:02:17