Tan*_*ira 5 wcf callback nettcpbinding wsdualhttpbinding
我遵循了这个教程(至少基于我的WCF,因为我需要同样的工作):http: //www.eggheadcafe.com/tutorials/wcf/b5ada8df-58c5-492f-b368-457b3a4f137c/notify-client-应用-使用的WCF,callbacks.aspx
它在我的电脑上工作得很好,但我需要通过互联网使用它.在尝试这样做时,我听说(通过互联网)最好使用netTcpBiding.
我将拥有一台能够了解在线客户数量的服务器.我想在服务器上的IIS上使用WFC服务,并使用Windows服务并通知它.我需要回调因为服务器有时必须能够在客户端上执行一些命令.
如果有人能帮助我,我会很高兴.
提前致谢,
编辑:
让自己明确:我无法让它在互联网上运作.你们能告诉我如何更改配置(Web.config e App.config)以使用netTcpBinding并通过互联网工作?
再次感谢,
编辑2:
我的WCFServiceApplication中的Web.config是:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IPCWatcherWCFService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="TiT.PCWatcher.Server.WCFService.Services.PCWatcherWCFServiceBehavior" name="TiT.PCWatcher.Server.WCFService.Services.PCWatcherWCFService">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IPCWatcherWCFService" contract="TiT.PCWatcher.Server.WCFService.Interfaces.IPCWatcherWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TiT.PCWatcher.Server.WCFService.Services.PCWatcherWCFServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我的WindowsService中的App.config是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IPCWatcherWCFService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:25145/Services/PCWatcherWCFService.svc"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IPCWatcherWCFService"
contract="PCWatcherWCFServiceReference.IPCWatcherWCFService"
name="WSDualHttpBinding_IPCWatcherWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
只是将其更改为netTcpBinding不起作用......
但我很高兴能够通过互联网运行这个...我在IIS上发布了WCFService.链接:
https://www2.tcenter.com.br/monitor/PCWatcherWCFService.svc
要么
http://www2.tcenter.com.br:8080/monitor/PCWatcherWCFService.svc
只是改变它应该通过互联网工作的配置?就像我说的,当地它运作得很好.
我认为只是将客户端上的端点地址更改为上面的URL之一就可以了,但它没有......
您链接的示例在WPF上托管服务.我不知道它是否适用于我的cenario ......
我想我会坚持使用DualHttpBinding,你不认为端口转发它对我的需求有好处,我可以在一个内部网中拥有很多客户端并让路由器决定他将发送哪些信息因为它不对吗?或者有一种方法可以让路由器通过同一个端口对每台连接到我的网络服务器的机器做出相应的响应?!(只是问,呵呵呵)
非常感谢提前,
编辑于21/06/2012:
谢谢你的阅读.我无法使该服务与LAN中的netTcpBinding一起使用.我做了我的cenario的模拟样本.就在这里.称为DualCommunicationTest.
当我开始这篇文章时,我只是想知道如何让这个cenarion在互联网上运行.只是.在我发布此处之前搜索解决方案期间,我认为netTcpBinding更好.所以我问了一下.这只是一个侧面问题.
那么......我目前对帖子的需求是:
要么
如何使我开发的样本与netTcpBinding一起工作,然后能够在互联网上使用它.(我很确定Clunky Coder教我第二部分,关于如何使用IIS和东西在互联网上发布net.tcp,非常感谢,但我还没能测试它,因为我无法还没做netTcp.)
对不起,如果我不够清楚,我的英语不太好.sry并再次感谢,很多.
netTcpBinding对于双工通信(与回调通信)更好,并且它比WSDualHttpBinding通过HTTP进行双工通信的首选绑定更高效.但是你不应该真正使用netTcpBinding互联网,虽然你在技术上可以并且可能有效,但使用的端口netTcpBinding可能(并且通常是)被互联网上的防火墙阻止.当您通过互联网发送内容时,它会产生大量跳跃并经过大量路由器和防火墙,并且无法保证这些路由器和防火墙将打开所有端口.但是如果你可以在客户端和服务器端点上打开端口(对于netTcp它是TCP 808)(通常通过路由器上的端口转发完成),它可能会起作用,但一般的建议是不要netTcpBinding通过互联网使用.说过我已经使用了几次我的服务,我的客户已经能够通过互联网使用服务而没有任何问题 - 在我转发客户端和服务器端的端口之后.
通常,对于通过Internet进行双工通信,您可以使用WSDualHttpBinding,如果您有Silverlight客户端(Silverlight不支持WSDualHttpBinding),则可以使用PollingDuplexHttpBinding.
我也建议你读这个.
编辑:
要更改要使用的示例netTcpBinding,只需更改配置文件中的绑定即可使用netTcpBinding而不是wsDualHttpBinding.看看这篇文章,它会做你发布的链接做什么,有netTcpBinding更多解释.
编辑20/06/2012:
让自己明确:我无法让它在互联网上运作.你们能告诉我如何更改配置(Web.config e App.config)以使用netTcpBinding并通过互联网工作?
似乎您能够netTcpBinding在局域网中使用该服务,因此您之前的问题现已得到修复,您现在无法在IIS中托管该服务并在线发布.当您的服务在局域网中工作时,一旦您在IIS中托管它并在客户端和服务器路由器上转发相应的端口,它将在Internet上工作,这是一种常见的情况,并且在线记录良好.为此,您必须将服务作为IIS网站中的应用程序托管.您需要确保您的服务具有指向服务位置的.svc文件,然后将App.Config(服务配置文件)的内容复制到新的web.config(与您的App在同一物理目录中) .config)并删除<host><baseAddresses>新创建的web.config 中的部分,将应用程序的物理路径指向服务主机上此服务的位置.一旦完成,只需确保编辑默认网站绑定以启用您的服务使用的特定绑定,netTcpBinding转到:网站 - >'编辑绑定...' - >'添加...'然后选择网络. tcp并为其分配端口.然后在您的应用程序上转到"高级设置"并启用net.tcp,netTcpBinding服务通常会具有http,net.tcp启用的协议.如果您遇到错误,请确保默认应用程序池(或您的网站正在使用的应用程序池)具有访问和读取服务所在服务器上的物理目录所需的权限.
编辑21/06/2012:
我刚刚下载了你的服务并在IIS中托管它并且托管很好,因为它使用HTTP而不是nettcp然后这意味着它在互联网上完美运行.如果您的服务很简单,并且您不希望使用它进行大量处理(通过它的外观,您只是尝试获取连接到它的客户端列表)然后坚持使用,wsDualHTTPBinding因为HTTP协议将适用于任何环境,你不必像你一样担心防火墙netTcpBinding.这就是我在IIS中托管服务所做的一切(并通过互联网提供):
转到IIS中的DefaultWebsite,右键单击,添加应用程序,在Alias下,只需为您的服务提供您希望在URL中看到的任何名称.选择默认应用程序池或ASP.NET 4.0应用程序池.
将物理路径指向.svc文件在计算机上的位置; 对我来说:
C:\Users\MyPC\Documents\DualCommunicationTest.Server\WcfServiceApp
就这么简单.