如何同时在HTTP和HTTPS中监听自托管的Azure Relay端点?

时间:2018-07-17 09:59:52

标签: c# azure wcf azureservicebus azure-servicebusrelay

我正在尝试使用Azure WCF中继,通过ServiceHost实例创建我的侦听器。它运作良好,但是我无法使其同时在HTTP和HTTPS中工作。我知道这似乎很奇怪,但这是我的要求。

这是我的代码:

Uri httpUri = ServiceBusEnvironment.CreateServiceUri(Uri.UriSchemeHttp, "MYNAMESPACE", "TEST");
Uri httpsUri = ServiceBusEnvironment.CreateServiceUri(Uri.UriSchemeHttps, "MYNAMESPACE", "TEST");
WebServiceHost sh = new WebServiceHost(typeof(TestAPI), httpsUri, httpUri);
sh.Open();

这是我的conf:

<bindings>
  <webHttpRelayBinding>
    <binding name="https" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" sendTimeout="00:15:00">
      <security mode="Transport" relayClientAuthenticationType="None"/>
    </binding>
    <binding name="http" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" sendTimeout="00:15:00">
      <security mode="None" relayClientAuthenticationType="None"/>
    </binding>
  </webHttpRelayBinding>
</bindings>
<services>
  <service name="TestAPI" behaviorConfiguration="default">
    <endpoint name="MobileEndpointHttps" contract="ITestAPI" binding="webHttpRelayBinding" bindingConfiguration="https" behaviorConfiguration="sbTokenProviderTest" address="" />
    <endpoint name="MobileEndpoint" contract="ITestAPI" binding="webHttpRelayBinding" bindingConfiguration="http" behaviorConfiguration="sbTokenProviderTest" address="" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="sbTokenProviderTest">
      <webHttp/>
      <serviceRegistrySettings discoveryMode="Public" />
      <transportClientEndpointBehavior>
        <tokenProvider>
          <sharedAccessSignature keyName="RootManageSharedAccessKey" key="MYKEY"/>
        </tokenProvider>
      </transportClientEndpointBehavior>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="default">
      <serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false"/>
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

httpGetEnabled和httpsGetEnabled似乎不需要使其单独运行,因此我将其禁用以避免netsh警告。

使用此配置,出现以下错误:

  

System.InvalidOperationException:合同为“ ITestAPI”的'sb://mynamespace.servicebus.windows.net/TEST/'处的ChannelDispatcher无法打开其IChannelListener。 ->   System.InvalidOperationException:一个注册已经存在   Uri'sb://mynamespace.servicebus.windows.net/TEST/'。

至少有可能吗?需要您的帮助:(

1 个答案:

答案 0 :(得分:0)

如果您仅使用安全模式=“ None”创建单个终结点,并且RelayClientAuthenticationType =“ None”不接受通过HTTP和HTTPS的通信吗?