简体   繁体   English

如何配置Windows Azure WCF服务Web角色以使用netTcpBinding?

[英]How to configure a Windows Azure WCF Service Web Role to work with netTcpBinding?

I have a WCF Service hosted on Windows Azure and I just recently changed it's contract to be a Duplex contract (to support a progress bar on the client). 我在Windows Azure上托管了WCF服务,最近我将其合同更改为双工合同(以支持客户端上的进度条)。 I first used the wsDualHttpBinding which worked well on my local machine, but as expected failed to work once I deployed it. 我首先使用wsDualHttpBinding,它在我的本地机器上运行良好,但是一旦我部署它就像预期的那样无法工作。

I am now trying to configure the service to work with netTcpBinding, but I'm getting the error "The protocol specified is not valid. The protocol 'tcp' for the binding named 'Endpoint1' is currently not supported.". 我现在正在尝试配置服务以使用netTcpBinding,但我收到错误“指定的协议无效。目前不支持名为'Endpoint1'的绑定的协议'tcp'。”

ServiceDefinition.csdef : ServiceDefinition.csdef:

<Endpoints>
  <InputEndpoint name="AlertsEndpoint" protocol="tcp" port="3030" />
</Endpoints>

Web.config: Web.config文件:

 <services>      
      <service name="AlertsService.AlertsService" behaviorConfiguration="AlertsServiceBehavior">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcp" contract="AlertsService.IAlertsService" />
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="MexTcp" contract="IMetadataExchange" />
      </service>
    </services>  

<bindings>
      <netTcpBinding>
        <binding name="NetTcp" />
      </netTcpBinding>
      <mexTcpBinding>
        <binding name="MexTcp"/>
      </mexTcpBinding>
</bindings>      

Web Roles hosting WCF services doesn't support the TCP protocol. 托管WCF服务的Web Roles不支持TCP协议。 You will need to host your WCF service in a Worker Role . 您需要在Worker Role托管WCF服务。

Web Roles: 网络角色:

Web roles in Windows Azure provide support for the HTTP and HTTPS protocols... Windows Azure中的Web角色提供对HTTP和HTTPS协议的支持......

Worker Roles: 工人角色:

...and allow the process to communicate externally using a variety of TCP-based application protocols with the WCF service by using the netTcpBindings binding ...通过使用netTcpBindings绑定,允许进程使用各种基于TCP的应用程序协议与WCF服务进行外部通信

You can enable whatever bindings you like for WCF on Azure in a web role by running startup scripts to enable say net.tcp ( after all its just IIS at the end of the day, although I admit its more of a pain than it should be! ). 您可以通过运行启动脚本启用net net.tcp来启用您在Web角色中为Azure上的WCF启用的任何绑定( 在一天结束之后它只是IIS之后,尽管我承认它比它应该更多的痛苦! )。 Full details can be seen at this article 在本文中可以看到完整的详细信息

Let me clarify this, as the answer given by @magnus johansson is not entirely correct. 让我澄清一下,因为@magnus johansson给出的答案并不完全正确。 Web Roles in Windows Azure most certainly do support tcp. Windows Azure中的Web角色肯定支持tcp。 However: Hosting WCF services in IIS are limited to HTTP only. 但是:在IIS中托管WCF服务仅限于HTTP。 If you choose to instantiate your own ServiceHost outside of IIS, then you'll have no problem with tcp. 如果您选择在IIS之外实例化您自己的ServiceHost ,那么您对tcp没有任何问题。

Here's an MSDN article describing WCF hosting in IIS, in more detail. 这是一篇MSDN文章 ,更详细地描述了IIS中的WCF托管。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM