gpt4 book ai didi

c# - WCF - IsOneway 的行为不像是 Oneway 操作

转载 作者:行者123 更新时间:2023-11-30 14:16:56 25 4
gpt4 key购买 nike

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

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

    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>

服务契约(Contract):

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

最佳答案

来自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.

这些会是你的问题吗?

关于c# - WCF - IsOneway 的行为不像是 Oneway 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6680411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com