加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:45:31 所属栏目:百科 来源:网络整理
导读:我已经在我的服务的一些方法上定义了OneWay属性,但它们的行为与Oneway调用不同.我的客户端等待呼叫完成并从服务返回.我假设Oneway操作是非阻塞操作,客户端不关心被调用函数会发生什么.它只是召唤并忘记它.这是对的吗? 问题: 在调用OperationContract2之后,
我已经在我的服务的一些方法上定义了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>

服务合约:

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

这些可能是你的问题吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读