Azure App.Config SharedAccessSignature错误

时间:2015-03-18 13:51:21

标签: wcf azure app-config

我正在尝试创建WCF服务。这将由Windows Azure Service Bus进行身份验证。

我的app.config如下所示

<tokenProvider>
<sharedAccessSignature keyName="" key=""/>
</tokenProvider>

在WCF测试客户端中运行WCF时,我遇到错误。

System.Configuration.ConfigurationErrorsException: Unrecognized element 'sharedAccessSignature'

由于

1 个答案:

答案 0 :(得分:0)

以下示例说明如何创建可通过Service Bus中继访问的WCF服务:

在.svc文件中定义这样的服务:

<%@ ServiceHost Language="C#" Debug="true" Service="ProblemSolver" CodeBehind="ProblemSolver.svc.cs" %>

请注意 ProblemSolver 实现了一个名为 IProblemSolver 的接口,用于指定服务合同。

我的web.config文件的相关部分如下所示:

<configuration>
...
<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="sharedAccessSignatureClientCredentials">
        <transportClientEndpointBehavior>
          <tokenProvider>
            <sharedAccessSignature keyName="RootManageSharedAccessKey" key="[YourSharedAccessSignature]" />
          </tokenProvider>
        </transportClientEndpointBehavior>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <netTcpRelayBinding>
      <binding name="default" />
    </netTcpRelayBinding>
  </bindings>
  <services>
    <service name="ProblemSolver">
      <endpoint address="sb://[YourServiceBusNamespace].servicebus.windows.net/solver" behaviorConfiguration="sharedAccessSignatureClientCredentials"
        binding="netTcpRelayBinding" bindingConfiguration="default"
        name="RelayEndpoint" contract="IProblemSolver" />
    </service>
  </services>
  <extensions>
    ...
  </extensions>
</system.serviceModel>
...
</configuration>