本文介绍了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 操作.为了更多信息,请参阅单向服务和使用服务使用客户.

有没有可能是你的问题?

Could any of those be your problem?

这篇关于WCF - IsOneway 的行为不像 Oneway 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 00:13