WCF - IsOneway 的行为不像 Oneway 操作

WCF - IsOneway 的行为不像 Oneway 操作

问题描述:

我已经在我的服务的一些方法上定义了 OneWay 属性,但它们的行为不像它的 Oneway 调用.My Client 等待调用完成并从服务返回.我假设 Oneway 操作是非阻塞操作,客户端不关心被调用函数会发生什么.它只是调用并忘记了它.正确吗?

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?

问题:调用 OperationContract2 后,我立即关闭代理,但我的客户端等待执行完成.

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

配置有问题吗?

服务器配置:

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

服务合同:

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

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

}

客户端代理:

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

来自 该属性的文档:

指定一个操作是单向操作仅意味着没有响应消息.如果连接可能会阻塞无法制作,或者出站消息非常大,或者如果服务无法足够快地读取入站信息.如果一个客户需要非阻塞调用,生成 AsyncPattern 操作.为了更多信息,请参阅单向服务和使用服务使用客户.

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?