Microsoft translator error

匿名 (未验证) 提交于 2019-12-03 01:40:02

问题:

I am trying to use microsoft translator and each time I am trying to create LanguageServiceClient I get an error.

try {     // Add the http header     string headerValue = GetAccessToken();     HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();     httpRequestProperty.Method = "POST";     httpRequestProperty.Headers.Add("Authorization", headerValue);      TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();     using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))     {         OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;         result = client.Detect("", textToTranslate);     } } catch (Exception ex) {     result = "Error: " + ex.Message; } 

The error:

Could not find default endpoint element that references contract 'TranslatorService.LanguageService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

Any suggestions?

回答1:

I discovered the error.

I was putting the service configuration in a class library where I do the translation logic. I tried to add it to the website configuration file "web.config" instead, and it's working now.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!