문제

I need such scenario: client sends message to server, not waiting for response, and don't care, if message was send properly.

using(host.RemoteService client = new host.RemoteService())
{
client.Open();

cliend.SendMessage("msg");
}

in scenario when firewall is on, or there is no connection to the internet, client dies at "SendMessage". I mean program stops to respond. I wish program don't care about the result. I mean if there is no connection, i wish program to go further, omitting "SendMessage" or sth like that.

What should I do, is there any solution for non blocking method?

도움이 되었습니까?

해결책

Try something like this in your service contract:

[OperationContract(IsOneWay=true)]
void Send(string message);

See the following link:

One Way Operation in WCF



Edit: OP was already using my suggested solution.

Suggested approaches to solve the issue - taken from MSDN (One-Way Services):

Clients Blocking with One-Way Operations

It is important to realize that while some one-way applications return as soon as the outbound data is written to the network connection, in several scenarios the implementation of a binding or of a service can cause a WCF client to block using one-way operations. In WCF client applications, the WCF client object does not return until the outbound data has been written to the network connection. This is true for all message exchange patterns, including one-way operations; this means that any problem writing the data to the transport prevents the client from returning. Depending upon the problem, the result could be an exception or a delay in sending messages to the service.

You can mitigate some of this problem by inserting a buffer between the client object and the client transport's send operation. For example, using asynchronous calls or using an in-memory message queue can enable the client object to return quickly. Both approaches may increase functionality, but the size of the thread pool and the message queue still enforce limits.

It is recommended, instead, that you examine the various controls on the service as well as on the client, and then test your application scenarios to determine the best configuration on either side. For example, if the use of sessions is blocking the processing of messages on your service, you can set the System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode property to PerCall so that each message can be processed by a different service instance, and set the ConcurrencyMode to Multiple in order to allow more than one thread to dispatch messages at a time. Another approach is to increase the read quotas of the service and client bindings.

다른 팁

Modify your attribute

[OperationContract(IsOneWay=true)]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top