开发者

Calling a service from a callback method in Client

I have a scenario where, upon receiving a command on one of the callback methods in client, the client needs to call another service. For example: In OnNewCommand() callback method client receives a message X. Now the client must call Service1() defined in the server. Note, Client has registered to the callback of Service1(). I can not use the sam开发者_开发知识库e client object to call Service1() since it results in dead-lock. So I use a new client object to call Service1(). But it hangs until timeout period expires. Any idea how to fix it? Thanks


I ran into the same kind of issue (callback hangs until timeout). I solved this problem by setting an attribute on the object implementing the callback interface:

[CallbackBehavior(UseSynchronizationContext = false)]


You may be getting a deadlock...

If possible define your callback methods to be “OneWay” and/or make a none blocking call to them, e.g. “begin_m1(...)”

Also check what the ConcurrencyMode you are using on the client and the server and see if you can use ConcurrencyMode.Reentrant or ConcurrencyMode.Muliple

See Chapter 5 of Programming WCF services for a good discussion of this


Same problem here. Had to add

[CallbackBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant, UseSynchronizationContext=false)]

above my callback class.


Off the top of my head, a couple of things to check for:

  • If you're using HTTP, increase the number of HTTP connections allowed from the client side to the HTTP server. This is 2 by default and might not be enough for your needs.
  • Make sure the throttling options in your WCF service are enough to handle all your required connections.


Probably your service has no ConcurencyMode set on it's behavior.

See something like [ServiceBehavior(ConcurencyMode=ConcurencyMode.Reentrant)] or similar attributes (like CallbackBehavior)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜