简体   繁体   中英

WCF - IsOneway is not behaving like it is Oneway operation

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);
    }
}

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM