WCF - 回调到客户端(双面打印?) [英] WCF - calling back to client (duplex ?)

查看:112
本文介绍了WCF - 回调到客户端(双面打印?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么样的解决方案选择问题.. 我有一个服务运行,可以从网站接收订单的服务器运行。 为了这台服务器多个客户(远程计算机)的某种联系。

I have a problem with what solution to choose.. I have a server running having a Service running that can receive orders from a website. To this server several client (remote computers) are connected somehow.

我真的想使用WCF的所有交际,但不知道这是可能的。

I would really like to use WCF for all comunication, but not sure it's possible.

我不想在配置他们的路由器的所有客户端的防火墙设置,因此客户必须连接到服务器。

I dont wanna configure all client firewall settings in their routers, so the clients would have to connect to the server.

但是,当有命令:收到所述服务器上,它应被转移到特定的客户端。

But when an order is recieved on the server, it should be transferred to a specific client.

一种解决方案可以让客户端连接使用的是双螺旋结合,但它必须以某种方式保持连接活动,以便能接收到的数据从服务器...这是一个很好的办法做到这一点?

One solution could be to have the Client connect using a duplex binding, but it will have to somehow keep the connection alive in order to be able to received data from server... Is this a good way to do this ??

通常情况下,连接超时,可能是一个很好的理由......

Normally the connection times out and probably for a good reason...

任何人有洞察力这个问题。

Anyone have insight to this problem.

THX很多的任何意见: - )

Thx alot for any advise :-)

最好的问候 瑟伦穆勒

推荐答案

这正是双工绑定被设计为。你有两个最好的选择是 NetTcpBinding的或<一href="http://msdn.microsoft.com/en-us/library/system.servicemodel.pollingduplexhttpbinding%28VS.95%29.aspx"相对=nofollow> PollingDuplexBinding 。

This is exactly what duplex bindings were designed for. The two best choices you have are NetTcpBinding or PollingDuplexBinding.

前者使用可能不适合你的客户,如果他们不是网络上的TCP协议。然而,它确实允许经由客户端发起的插座的双向通信。因此客户端不需要能够接受输入连接。最近,我用这一个项目,它工作得很好。这也是非常敏感。当客户端应用程序关闭,服务器上的会话立即结束。

The former uses a TCP protocol which may not be suitable for your clients if they aren't on your network. However, it does allow two-way communication over a client-initiated socket. So the client doesn't need to be able to accept incoming connections. I recently used this on a project and it works very well. It's also very responsive. When client applications close, the session on the server immediately ends.

第二个选项,PollingDuplexBinding包含在Silverlight中的SDK。它采用客户端发起的长HTTP请求。请求等待需要走出去到客户端,他们到达时,客户要求退货的消息。然后客户端发起一个新的HTTP请求发送回服务器。换言之,客户机总是有一个挂起的HTTP请求。这种运作良好,在防火墙,当你在处理互联网客户端进行使用。然而,我发现这是不一样的反应NetTcpBinding的。也可能是我做错了什么,但它似乎是尝试发送回调废弃的客户端会话花了一段时间超时。

The second option, PollingDuplexBinding is included in the Silverlight SDK. It uses a client-initiated "long" HTTP request. The request waits for messages that need to go out to the client and when they arrive, the client request returns. The client then initiates a new HTTP request back to the server. In other words, the client always has a pending HTTP request. This works well over firewalls and should be used when you're dealing with internet clients. However, I've found this to be not as responsive as NetTcpBinding. I may have been doing something wrong but it seemed like attempts to send callbacks to abandoned client sessions took a while to "time out".

下面是从我最近的项目是用于NetTcpBinding的进行双工通信的配置文件的例子。需要注意的是,除了一些调整,我感到非常使用默认值,此绑定pretty的以服务节流。但是,有各种各样的东西你可以调整,如receiveTimeout,inactivityTimeout,等等。

Here's an example of the configuration file from my recent project that used NetTcpBinding for duplex communication. Note that other than some tweaks to service throttling I am pretty much using the defaults for this binding. But there's all kinds of things you can tweak such as receiveTimeout, inactivityTimeout, etc.

<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>


[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

这篇关于WCF - 回调到客户端(双面打印?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆