0

我正在尝试使用微软翻译器,每次尝试创建时LanguageServiceClient都会出错。

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”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

有什么建议么?

4

1 回答 1

3

我发现了错误。

我将服务配置放在我执行翻译逻辑的类库中。我尝试将它添加到网站配置文件“web.config”中,现在它正在工作。

于 2011-12-12T09:43:03.620 回答