3

I have defined OneWay attribute on some of the methods of my service but they are not behaving like its a Oneway call. My Client waits for the call to complete and return from the service. I am assuming that Oneway operations are non-blocking operations and client doesnt care what happens to the called function. It just calls and forgets abt it. Is it correct?

Problem: After calling OperationContract2, I immediately close the proxy but my client waits for the exection to complete.

    if (((ICommunicationObject)myServices).State == CommunicationState.Opened)
        {
        ((ICommunicationObject)myServices).Close();
        }

Is there something wrong with the configs?

Server Config:

  <netTcpBinding>
    <binding name="GoCustomBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="0" maxReceivedMessageSize="2147483647">
    </binding>
  </netTcpBinding>

Service Contract:

[ServiceContract]
public interface IMyServices
{
    [OperationContract(IsOneWay = true, Action = "*")]
    void OPeration1(List<int> someIds);

    [OperationContract(IsOneWay = true)]
    void OPeration2(SomeClass p1);

}

Client Proxy:

[ServiceContract]
public interface IMyServices
{
    [OperationContract(IsOneWay = true, Action = "*")]
    void Operation1(List<int> someIds);

    [OperationContract(IsOneWay = true)]
    void Operation2(SomeClass p1);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ServiceClient : ClientBase<IMyServices>, IMyServices
{
    public void ScheduleOptimization(List<int> someIds)
    {
        Channel.Operation1(routeID);
    }

    public void Operation1(SomeClass p1)
    {
        Channel.Operation2(pasDataMsg);
    }
}
Asdfg
  • 11,362
  • 24
  • 98
  • 175

1 Answers1

7

From the documentation for that attribute:

Specifying that an operation is a one-way operation means only that there is no response message. It is possible to block if a connection cannot be made, or the outbound message is very large, or if the service cannot read inbound information fast enough. If a client requires a non-blocking call, generate AsyncPattern operations. For more information, see One-Way Services and Consuming Services Using a Client.

Could any of those be your problem?

dkackman
  • 15,179
  • 13
  • 69
  • 123
  • ConcurrencyMode is set to ConcurrencyMode.Multiple and InstanceContextMode is set to InstanceContextMode.PerCall. I think i may have to implement AsyncPattern. Do you have any pointers for that? – Asdfg Jul 13 '11 at 14:29
  • Also the thing is that its a Void operation so why bother to return something? – Asdfg Jul 13 '11 at 14:47
  • So i marked my methods as AsyncPattern = true and return type of Operation2 is now IAsyncResult. What should i actually return? – Asdfg Jul 13 '11 at 14:54
  • To you second comment: the issue isn't the return (as there will be no return). The issue is the time it takes to make the actual call. The invocation of the method is being done synchronously and the client code is waiting until that invocation is made; which I would assume means all of the overhead of establishing the connection and getting the message on to the wire. – dkackman Jul 13 '11 at 15:39
  • Take a look at these for implementing the async pattern: http://msdn.microsoft.com/en-us/library/ms734701.aspx http://msdn.microsoft.com/en-us/library/ms731177.aspx – dkackman Jul 13 '11 at 15:40
  • I implemented Async pattern thinking i will be able to release the client without completing the server-side execution but no luck. It does make Async call but it still behaves the same way. I cant close the connection until the execution is completed. But this was helpful. I learnt how can i make "Oneway" Service calls that return results. It was worth of an effort. – Asdfg Jul 14 '11 at 16:12