private static String TranslateMethod(string authToken, string text, string lang) {
// Add TranslatorService as a service reference, Address:http://api.microsofttranslator.com/V2/Soap.svc
TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();
//Set Authorization header before sending the request
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Method = "POST";
httpRequestProperty.Headers.Add("Authorization", authToken);
// Creates a block within which an OperationContext object is in scope.
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) {
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
//Keep appId parameter blank as we are sending access token in authorization header.
return client.Translate("", text, "en", lang, "text/html", "general");
}
}