Asked by:
Bing Translation Api access via SOAP interface from Perl SOAP::Lite

Question
-
Hello all!
I write perl module for access to Bing Translation Api - Lingua::Translate::Bing. I want to use SOAP interface, but i can't it do. I already read this page "How to Call a .NET-based Web Service Using the SOAP::Lite Perl Library" , but it did't help me.
For example, i tried code:
sub getLanguagesForTranslate { my ($self) = @_; my $token = $self->getAccessToken(); $SOAP::Constants::DO_NOT_USE_CHARSET = 1; my $soap = SOAP::Lite->ns('http://api.microsofttranslator.com', 'tns') ->readable(1) ->proxy('http://api.microsofttranslator.com/V2/Soap.svc') ->on_action(sub {return '"http://api.microsofttranslator.com/V2/LanguageService/GetLanguagesForTranslate"'}); $soap->transport->http_request->header("Authorization" => $token); my $method = SOAP::Data->name('GetLanguagesForTranslate')->attr({xmlns => 'http://api.microsofttranslator.com/V2/LanguageService'}); my @params = ( SOAP::Data->name("appId")->type("string")->value("")); my $answer = $soap->call($method => @params); return $answer->result; }
but it return "Unhandled Service Exception".
My SOAP request with this code is:
POST http://api.microsofttranslator.com/V2/Soap.svc HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Authorization: Bearer http%253a%252f%252fschemas.xmlsoap.org%252fws%252f2005%252f05%252fidentity%252fclaims%252fnameidentifier%3DBingTranslationTest%26http%253a%252f%252fschemas.microsoft.com%252faccesscontrolservice%252f2010%252f07%252fclaims%252fidentityprovider%3Dhttps%253a%252f%252fdatamarket.accesscontrol.windows.net%252f%26Audience%3Dhttp%253a%252f%252fapi.microsofttranslator.com%26ExpiresOn%3D1359415215%26Issuer%3Dhttps%253a%252f%252fdatamarket.accesscontrol.windows.net%252f%26HMACSHA256%3Dog2suDViN3n7NCNakgXBjco%252f5OKhxSMNXvm8Ti4Q73U%253d
Content-Length: 622
Content-Type: text/xml
SOAPAction: "http://api.microsofttranslator.com/V2/LanguageService/GetLanguagesForTranslate"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://api.microsofttranslator.com"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetLanguagesForTranslate xmlns="http://api.microsofttranslator.com/V2/LanguageService">
<appId xsi:type="xsd:string" />
</GetLanguagesForTranslate>
</soap:Body>
</soap:Envelope>Where i was wrong?
Thanks for you attention!
Monday, January 28, 2013 11:20 PM
All replies
-
Hi Milovidov,
The SOAPAction should be: “http://api.microsofttranslator.com/V2/Soap.svc/LanguageService/GetLanguagesForTranslate”
NOT "http://api.microsofttranslator.com/V2/LanguageService/GetLanguagesForTranslate".
Would you try this? Let us know how it goes. Microsoft Translator Team
Tuesday, January 29, 2013 3:58 AM -
Yes, i tried this. Now my code is:
sub getLanguagesForTranslate { my ($self) = @_; my $token = $self->getAccessToken(); $SOAP::Constants::DO_NOT_USE_CHARSET = 1; my $soap = SOAP::Lite->ns('http://api.microsofttranslator.com', 'tns') ->readable(1) ->proxy('http://api.microsofttranslator.com/V2/Soap.svc') ->on_action(sub {return '"http://api.microsofttranslator.com/V2/Soap.svc/LanguageService/GetLanguagesForTranslate"'}); $soap->transport->http_request->header("Authorization" => $token); my $method = SOAP::Data->name('GetLanguagesForTranslate')->attr({xmlns => 'http://api.microsofttranslator.com/V2/Soap.svc/LanguageService'}); my @params = ( SOAP::Data->name("appId")->type("string")->value("")); my $answer = $soap->call($method => @params); return $answer->result; }
Ana my request is:
POST http://api.microsofttranslator.com/V2/Soap.svc HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Authorization: Bearer http%253a%252f%252fschemas.xmlsoap.org%252fws%252f2005%252f05%252fidentity%252fclaims%252fnameidentifier%3DBingTranslationTest%26http%253a%252f%252fschemas.microsoft.com%252faccesscontrolservice%252f2010%252f07%252fclaims%252fidentityprovider%3Dhttps%253a%252f%252fdatamarket.accesscontrol.windows.net%252f%26Audience%3Dhttp%253a%252f%252fapi.microsofttranslator.com%26ExpiresOn%3D1359451370%26Issuer%3Dhttps%253a%252f%252fdatamarket.accesscontrol.windows.net%252f%26HMACSHA256%3DC19heidehgLkufVpYKv1xnCcla4weld6gdvs5pYAGVU%253d
Content-Length: 631
Content-Type: text/xml
SOAPAction: "http://api.microsofttranslator.com/V2/Soap.svc/LanguageService/GetLanguagesForTranslate"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://api.microsofttranslator.com"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetLanguagesForTranslate xmlns="http://api.microsofttranslator.com/V2/Soap.svc/LanguageService">
<appId xsi:type="xsd:string" />
</GetLanguagesForTranslate>
</soap:Body>
</soap:Envelope>
But, i also have error response with other sense:
HTTP/1.1 500 Internal Server Error
Date: Tue, 29 Jan 2013 09:12:49 GMT
Content-Length: 785
Content-Type: text/xml; charset=utf-8
Client-Date: Tue, 29 Jan 2013 09:12:49 GMT
Client-Peer: 131.253.14.87:80
Client-Response-Num: 1
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action 'http://api.microsofttranslator.com/V2/Soap.svc/LanguageService/GetLanguagesForTranslate' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault></s:Body></s:Envelope>
Tuesday, January 29, 2013 9:16 AM -
Hi Milovidov,
The SOAPAction should be: “http://api.microsofttranslator.com/V2/Soap.svc/GetLanguagesForTranslate”
NOT "http://api.microsofttranslator.com/V2/Soap.svc/LanguageService/GetLanguagesForTranslate".
Sorry for not catching this the first time. Would you try this? Let us know how it goes. Microsoft Translator Team
Tuesday, January 29, 2013 3:59 PM -
It make the same error.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action 'http://api.microsofttranslator.com/V2/Soap.svc/GetLanguagesForTranslate' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault></s:Body></s:Envelope>
- Edited by Milovidov Mikhail Tuesday, January 29, 2013 5:26 PM
Tuesday, January 29, 2013 5:25 PM -
Hello. I'm trying to use Bing Translator SOAP API (due to in HTTP API I'm getting 414 request too long for not so big requests due to UTF-8 serialization).
So, I'm using Ruby and Savon SOAP toolkit.
My workflow as follows (access token getting not shown):
WSDL_URI = 'http://api.microsofttranslator.com/V2/soap.svc?wsdl' 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>
If I'm trying to adjust SOAPAction header as noted above this question
But I'm getting other error:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <s:Fault> <faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode> <faultstring xml:lang="en-US">The message with Action 'http://api.microsofttranslator.com/V2/Soap.svc/Translate' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring> </s:Fault> </s:Body> </s:Envelope>
What's may be wrong?
- Edited by Envek Monday, October 7, 2013 8:00 AM use markup
Monday, October 7, 2013 7:57 AM -
Mikhail, in my case it was XML namespace issue. All tags inside body tag MUST be in namespace with address 'http://api.microsofttranslator.com/V2'. Possibly it's your issue too. See the stackoverflow questiuon no. 19226148.Tuesday, October 8, 2013 5:59 AM