如何将system.serviceModel放入ServiceConfiguration.cscfg(Windows Azure)

时间:2012-08-01 23:40:47

标签: azure web-config

我有以下代码(适用于Microsoft Translator)

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_LanguageService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://api.microsofttranslator.com/V2/soap.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService" contract="TranslatorService.LanguageService" name="BasicHttpBinding_LanguageService" />
        </client>
    </system.serviceModel>

它在web.config并且运作良好。现在我需要为Azure Worker Role添加一些翻译功能,因此我收到错误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.

我已经找到解决方案是将上述设置放到ServiceConfiguration.cscfg,但是如何?我尝试了很多位置但是所有错误都无法部署。请帮忙

1 个答案:

答案 0 :(得分:5)

ServiceConfiguration.cscfg只能包含Azure特定配置(例如实例数,配置设置,指纹......)。

每当您需要进行常规的.NET配置(例如WCF)时,您只需为您的辅助角色创建一个 app.config ,就像您要用于控制台应用程序并将您的配置放入这里。请注意,如果要将其添加到app.config中,则问题中的示例配置不完整。你应该把它包裹起来:

<?xml version="1.0"?>
<configuration>

  ...

</configuration>