web services - Bing Translation Api access via SOAP interface from Ruby -


i'm trying use bing translator soap api (due in http api i'm getting 414 "request long" not big requests due utf-8 serialization).

so, i'm playing bing_translator gem source trying switch http inerface soap 1 using savon soap toolkit.

my workflow follows (access token getting function not shown):

wsdl_uri = 'http://api.microsofttranslator.com/v2/soap.svc?wsdl'  get_access_token client = savon.client(wsdl: wsdl_uri, headers: {'authorization' => "bearer #{@access_token['access_token']}"})  params = {   'from'        => 'ru',   'to'          => 'en',   'text'        => 'Это текст для перевода',   'category'    => 'general',   'contenttype' => 'text/plain' }  result = client.call(:translate, message: params) 

then soap request executes:

soap request: http://api.microsofttranslator.com/v2/soap.svc  authorization: bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=invest_amurobl_ru&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&audience=http%3a%2f%2fapi.microsofttranslator.com&expireson=1381128612&issuer=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&hmacsha256=mw41pmmgw2n6zvagrxtwfr0vwmjuyimltiyd9pa9mqa%3d soapaction: "http://api.microsofttranslator.com/v2/languageservice/translate" content-type: text/xml;charset=utf-8 content-length: 454  <?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> <wsdl:translate> <to>en</to> <text>Это текст для перевода</text> <category>general</category> <contenttype>text/html</contenttype> <from>ru</from> </wsdl:translate> </env:body> </env:envelope> 

and i'm getting error 500: unhandled service exception

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:body> <s:fault> <faultcode>s:client</faultcode> <faultstring xml:lang="en-us">unhandled service exception</faultstring> <detail> <int xmlns="http://schemas.microsoft.com/2003/10/serialization/">1</int> </detail> </s:fault> </s:body> </s:envelope> 

what's may wrong? can using bing translator soap api diff soap-messages yourself? advices how troubleshoot this.

thanks attention.

edit:

i've checked api soapui, @steffenroller advices , works. here xml generated soapui (values inserted hand):

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://api.microsofttranslator.com/v2">    <soapenv:header/>    <soapenv:body>       <v2:translate>          <!--optional:-->          <v2:text>Текст, который я хочу перевести</v2:text>          <!--optional:-->          <v2:from>ru</v2:from>          <!--optional:-->          <v2:to>en</v2:to>          <!--optional:-->          <v2:contenttype>text/plain</v2:contenttype>          <!--optional:-->          <v2:category>general</v2:category>       </v2:translate>    </soapenv:body> </soapenv:envelope> 

as can see difference tags inside <body> in v2 namespace. in xml, generated savon namespace isn't present @ all.

so, question is: how instruct savon use correct namespace tags inside message body?

although, think, savon bug, i'll file developers, soapui have generated correct xml same wsdl, , savon doesn't.

okay. known bug: savon issue #340. it's related composite wsdl files , won't bi fixed in current major release :-(

so, in our case need tell savon, our namespace is, it's name (just align wsdl) , prepend each tag's name namespace.

the correct code looks this:

require 'savon'  access_token = "http%3a%2f%2fschemas.xmlsoap.org%2fws...ca9tes%3d"  client = savon.client(   wsdl: 'http://api.microsofttranslator.com/v2/soap.svc?wsdl',   namespace: 'http://api.microsofttranslator.com/v2',   namespace_identifier: :v2,   headers: {'authorization' => "bearer #{access_token}"}, )  params = {   'v2:text'        => 'Это текст для перевода',   'v2:from'        => 'ru',   'v2:to'          => 'en',   'v2:contenttype' => 'text/plain',   'v2:category'    => 'general', }  result = client.call(:translate, message: params)  puts result.body[:translate_response][:translate_result] 

any advices , corrections welcome. thanks.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -