English 中文(简体)
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 same 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)





相关问题
Run EXE from client side

I need run an exe file from client side. The Exe file exist in my C: Directory. I need run this exe file from my WEB site. How can I co this?

Security in PHP

I ve written some PHP scripts to do some server-side work on a headless linux server machine on a LAN. For example, I have http://ipadress/php/operations.php?operation=registerUser&uName=X&...

EMAIL server FSP model

For my assignment I need to develop FSP model for email server and client. I manage to write simple model which describes one user, server and his mailbox, but I am having problems changing this ...

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

ServiceContractGenerator vs ServiceDescriptionImporter

I m trying to build a light-weight SOAP client without using Add Service Reference. Ideally, this client should work for as many services as possible. Currently, it uses ServiceDescriptionImporter to ...

Simple server and client request/response in C#

OK. I just want to know if this can be done. I m using C# asp.net language. I want to send a structure to a webserver from a webpage (much like you you can pass a structure to a function). The ...

热门标签