微软翻译错误 [英] Microsoft translator error

查看:252
本文介绍了微软翻译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Microsoft翻译程序,每次尝试创建LanguageServiceClient时都会出现错误.

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;
}

错误:

找不到引用合同的默认端点元素 ServiceModel客户端中的"TranslatorService.LanguageService" 配置部分.这可能是因为没有配置文件 为您的应用程序找到,或者因为没有匹配的终结点元素 可以在client元素中找到该合同.

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.

有什么建议吗?

推荐答案

我发现了错误.

我将服务配置放在一个类库中,负责翻译逻辑.我尝试将其添加到网站配置文件"web.config"中,并且现在可以正常使用.

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.

这篇关于微软翻译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆