1

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?

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
santBart
  • 2,466
  • 9
  • 43
  • 66

2 Answers2

5

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.

Andrija
  • 14,037
  • 18
  • 60
  • 87
Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
  • " using asynchronous calls " means like trying to connect to endpoint from different thread or sth like that? Sorry for dummy question I'm quite new to WCF – santBart Feb 13 '13 at 14:46
  • Try what's written in the 3rd paragraph first - set the System.ServiceModel.ServiceBehaviorAttribute.InstanceContextMode property to PerCall (...), and set the ConcurrencyMode to Multiple – Rui Jarimba Feb 13 '13 at 14:49
  • @santBart: This may help too: http://stackoverflow.com/questions/400798/how-to-make-a-call-to-my-wcf-service-asynchronous – Rui Jarimba Feb 13 '13 at 17:04
  • I was wondering if I can use sth like "client.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(1);" when it works ok it takes 2 seconds to send, in case of exception "The request channel timed out attempting to send after 00:00:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout." it lasts 8 seconds. I am looking for possibly easiest solution. – santBart Feb 14 '13 at 11:38
  • @santBart: in my answer you can find different approaches to solve your problem, now it's up to you to try them till you find one that suits you. – Rui Jarimba Feb 14 '13 at 12:24
0

Modify your attribute

[OperationContract(IsOneWay=true)]
Manish
  • 510
  • 2
  • 12
  • It has already such atribute. ServiceContract(SessionMode=SessionMode.NotAllowed) OperationContract(IsOneWay=true) – santBart Feb 13 '13 at 12:47