Mül*_*rDK 4 .net wcf wcf-binding .net-3.5
我有一个问题,选择什么解决方案..我有一个服务器正在运行服务运行,可以从网站接收订单.对于此服务器,以某种方式连接了多个客户端(远程计算机).
我真的想使用WCF进行所有通信,但不确定它是否可行.
我不想在他们的路由器中配置所有客户端防火墙设置,因此客户端必须连接到服务器.
但是,当在服务器上收到订单时,应将其转移到特定客户端.
一种解决方案可能是让客户端使用双工绑定进行连接,但是必须以某种方式保持连接处于活动状态才能从服务器接收数据...这是一个很好的方法吗?
通常连接超时,可能是有充分理由的......
任何人都有这个问题的见解.
很多任何建议:-)
最好的问候SørenMüller
这正是双工绑定的设计目标.您拥有的两个最佳选择是NetTcpBinding或PollingDuplexBinding.
前者使用TCP协议,如果它们不在您的网络上,可能不适合您的客户.但是,它确实允许通过客户端启动的套接字进行双向通信.因此客户端不需要能够接受传入的连接.我最近在一个项目上使用它,它运行得很好.它也非常敏感.客户端应用程序关闭时,服务器上的会话立即结束.
第二个选项PollingDuplexBinding包含在Silverlight SDK中.它使用客户端发起的"长"HTTP请求.请求等待需要发送到客户端的消息,当它们到达时,客户端请求返回.然后,客户端将新的HTTP请求发送回服务器.换句话说,客户端始终具有挂起的HTTP请求.这适用于防火墙,应该在您处理Internet客户端时使用.但是,我发现这不像NetTcpBinding那样响应.我可能一直在做错事,但似乎尝试将回调发送到废弃的客户端会话需要一段时间才能"超时".
这是我最近项目中使用NetTcpBinding进行双工通信的配置文件的示例.请注意,除了对服务限制的一些调整之外,我几乎使用此绑定的默认值.但是你可以调整各种各样的东西,比如receiveTimeout,inactivityTimeout等.
<configuration>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="65535"
maxConcurrentSessions="65535"
maxConcurrentInstances="65535" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding maxConnections="65535">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="BroadcastService">
<endpoint address="" binding="netTcpBinding" contract="BroadcastService" />
</service>
</services>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
[ServiceContract( CallbackContract = typeof( IBroadcastCallback ) )]
[ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple )]
public class BroadcastService : IDisposable
{
[OperationContract(IsInitiating=true)]
public long Subscribe( Guid clientID )
{
// clients call this to initiate the session
}
[OperationContract(IsOneWay = true)]
public void Publish( BroadcastMessage message )
{
// client calls this to broadcast a message to
// all other subscribed clients via callback
}
}
[ServiceContract( Name = "BroadcastCallback" )]
public interface IBroadcastCallback
{
[OperationContract( IsOneWay = true, AsyncPattern = true )]
IAsyncResult BeginBroadcast(BroadcastMessage Message, AsyncCallback callback, object state);
void EndBroadcast( IAsyncResult asyncResult );
} // interface
Run Code Online (Sandbox Code Playgroud)