根据MSDN,“ MaxConnections”参数表示:
NetTcpBinding.MaxConnections属性控制要为客户端上的后续重用而池化的最大连接数,以及允许在服务器上待处理的最大连接数。
“待处理”一词是什么意思?
我有一个使用netTcpBinding和回调方法的主机/客户端WCF服务和客户端.
<bindings>
<netTcpBinding>
<binding name="tcp_Unsecured" receiveTimeout="00:01:00" sendTimeout="00:01:00">
<security mode="None" />
<reliableSession enabled="true" ordered="true" inactivityTimeout="00:10:00"/>
</binding>
</netTcpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
代理
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://dotnetaddict.dotnetdevelopersjournal.com/wcf.samples", ConfigurationName="AlarmServer", CallbackContract=typeof(AlarmServerCallback), SessionMode=System.ServiceModel.SessionMode.Required)]
public interface AlarmServer
{
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://dotnetaddict.dotnetdevelopersjournal.com/wcf.samples/AlarmServer/RegisterAlarm")]
void RegisterAlarm(System.DateTime alarmTime, string clientName, string reminderMessage);
[System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://dotnetaddict.dotnetdevelopersjournal.com/wcf.samples/AlarmServer/unRegisterAlarm")]
void unRegisterAlarm(string clientName);
[System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://dotnetaddict.dotnetdevelopersjournal.com/wcf.samples/AlarmServer/broadcastMessage")]
void broadcastMessage(string msg);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface AlarmServerCallback
{
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://dotnetaddict.dotnetdevelopersjournal.com/wcf.samples/AlarmServer/SignalAlarm")]
void SignalAlarm(string reminderMessage);
[System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://dotnetaddict.dotnetdevelopersjournal.com/wcf.samples/AlarmServer/displayMessage")]
void displayMessage(string msg);
}
Run Code Online (Sandbox Code Playgroud)
带回调的客户端实例
public MainForm() …Run Code Online (Sandbox Code Playgroud) 我正在寻找通过慢速卫星连接创建数据查询WCF服务,我真的很喜欢WCF数据服务.我看到的问题是HTTP是一种非常冗长的格式,因为我所做的一切都是内部和.NET,是否可以使用NetTcpBinding来减少一些开销?
这甚至可能吗?可取?
(请阅读评论,因为我有一个修复)
嗨,
我创建了一个WCF服务,我在Windows 7上使用.net 4.0在IIS 7.5中托管.
该服务托管在http和net.tcp上.
我已经使用WcfTestClient测试了我的服务,它似乎通过basicHttp和netTcp正常工作.
但是,当我尝试通过我的ASP.NET网站使用此服务时,我在尝试通过nettcp时收到错误
我的客户端点如下所示
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Generic_HttpBinding" sendTimeout="00:01:00" receiveTimeout="00:01:00" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000000">
<security mode="None"/>
<readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000"/>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="Generic_Binding" sendTimeout="00:01:00" receiveTimeout="00:01:00" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000000">
<security mode="None"/>
<readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000"/>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint name="EndPointHttp" address="http://localhost:43/Service/MyService.svc" binding="basicHttpBinding" bindingConfiguration="Generic_HttpBinding" contract="NameSpace.Services.Contracts.IService"></endpoint>
<endpoint name="EndPoint" address="net.tcp://localhost:42/Service/MyService.svc" binding="netTcpBinding" bindingConfiguration="Generic_Binding" contract="NameSpace.Services.Contracts.IService"></endpoint>
</client>
Run Code Online (Sandbox Code Playgroud)
现在我以完全相同的方式调用服务,只需交换我的终点名称
var factory = new ChannelFactory<IService>(SuppliedEndpointName);
factory.Open();
var proxy = factory.CreateChannel();
var result …Run Code Online (Sandbox Code Playgroud) 我需要在Windows Azure项目中即时更改一些配置设置 - 它们需要通过Web服务调用进行更改(通过平台API或Azure管理站点更新应用程序的配置不是此处的选项).
该项目有多个Web和worker角色 - 所有这些角色在更改时都需要了解新配置.
配置持久保存到持久存储,并且它还在运行时在静态变量中缓存.
我的解决方案是在我的角色上创建一个内部(tcp)端点,并使用它来遍历这些角色中的所有角色和实例,动态创建客户端,并告诉实例有关新设置的信息.(几乎完全相同:http://msdn.microsoft.com/en-us/gg457891)
起初我在WebRole的RoleEntryPoint中启动了一个ServiceHost ......我很困惑,为什么当我逐步完成通信(静态变量设置正确)时,一切似乎都工作正常 - 但是当我进行其他webservice调用时,静态变量似乎"忘记了"我设置的内容.
本地和Azure登台环境都是如此.
此时我意识到,因为我们使用的是完整的IIS模式,所以RoleEntryPoint和Web服务在两个独立的进程中运行 - 一个在Azure的存根中,一个在IIS中.
"不成问题"我说,我只是将从ServiceEntryPoint启动ServiceHost的代码行移动到global.asax中 - 此时ServiceHost将在与站点其余部分相同的进程中启动 - 而静态变量将是相同的.
这是我遇到问题的地方; 这在我在dev环境中运行的本地机器上运行良好.一旦我部署到分段,我就开始收到错误电子邮件,说明用于连接服务的通道无法关闭,因为它处于"故障状态".
题:
跟进:
通过远程桌面,我学到了几件有趣的东西:
默认情况下,Azure WebRoles上未安装非HTTP激活.我相信这可以通过启动脚本来克服:
start/w pkgmgr/iu:WCF-NonHTTP-Activation;
Web角色在IIS中创建的网站默认情况下未启用net.tcp协议.我也相信这可以通过启动脚本来克服:
%systemroot%\ system32\inetsrv\appcmd.exe设置应用"网站名称在这里"/enabledProtocols:https,http,net.tcp
我没有时间采取这种方式,因为最后期限迫使我暂时实施一些变通方法.
一些与此主题相关的有用链接:
http://msdn.microsoft.com/en-us/magazine/cc163357.aspx
http://forums.iis.net/t/1160443.aspx
我遵循了这个教程(至少基于我的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" …Run Code Online (Sandbox Code Playgroud) 是否可以像这样拥有WCF服务配置:
<service behaviorConfiguration="WcfService1.Service1Behavior"
name="WcfService1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfService1.IService1">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/netTcpService" />
</baseAddresses>
</host>
</service>
Run Code Online (Sandbox Code Playgroud)
并将它托管在Visual Studio 2008附带的ASP.NET开发服务器上,或者我是否必须在IIS 7中托管服务或在托管应用程序/ Windows服务中自托管它?
感谢您的见解!
被调用的方法是否可以访问绑定级别的信息,例如原始IP地址?
我知道如何为NTLM身份验证配置basicHttpBinding,但无法找到为netTcpBinding执行相同操作的方法.
netTcpBinding是否支持NTLM?如果是这样,如何强制WCF服务使用NTLM?
BTW由于某种原因使用身份元素的众所周知的方法根本不起作用.我正在寻找类似的东西 - clientCredentialType ="Ntlm"但是对于tcp.这是basicHttp设置:
<basicHttpBinding>
<binding name="BasicHttpBinding">
<security mode ="TransportCredentialOnly">
<transport clientCredentialType ="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud) 我们使用SecurityMode.None运行NetTcpBinding.
现在我们还想要加密发送的数据.将SecurityMode设置为Transport似乎还不够,因为虽然服务器已启动,但客户端无法再连接到服务器(在此更改之前有效).
我还需要改变什么?