繁体   English   中英

序列化之前要修改的WCF服务引用类型属性

[英]WCF Service reference type property to be modified before serialization

假设我们有两个服务合同的服务。

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IServiceCallback))]
public interface IService : IDisposable
{
    [OperationContract]
    [ServiceKnownType(typeof(ServiceProperty))]
    [FaultContract(typeof(ServiceMethodFaultException))]
    [ServiceKnownType(typeof(object[]))]
    ServiceProperty GetServicePropertyAbc();

    [OperationContract]
    void ModifyServicePropertyAbc();
}

以及实现IService的服务:

public class ServiceBase : IService
{
   ServiceProperty abc;

   public ServiceProperty GetServicePropertyAbc()
    {
          //somelogic
          return abc;
    }

   public void ModifyServicePropertyAbc()
   {
    abc = new ServiceProperty();
    abc.SomeProperty = 100 * 100;
   }
}

我们有:

  • 使用ServiceBase作为代理的“客户端1”

  • 使用ServiceBase作为代理的“客户端2”

两个客户端的服务主机相同。

有以下情况:

  • 步骤1成功由“客户端1”调用GetServiceProperty()

  • 步骤2 GetServiceProperty()返回abc;

  • 步骤3 abc被序列化为XML

  • 步骤4 “客户端1”正在获取XML响应

是否有可能在步骤2步骤3之间 ,“客户端2”可以使用ModifyServicePropertyAbc()修改ServiceProperty abc ,因此“客户端1”将已经修改“ abc”?

假设GetServicePropertyAbc()方法中存在逻辑,该逻辑可锁定abc (我们的代码是100%线程安全的,但是我们担心退出GetServiceProperty()范围时会发生什么)。

我只是想知道是否有可能在步骤2和步骤3之间修改ServiceProperty abc ,或者WCF保证它不会被修改?

ServiceProperty是一种引用类型,它确实很复杂(不能用值类型代替)。

最有可能的情况是,由于您已签订服务合同,因此每次致电时,您都将创建一个新的服务实例。 对于基于会话的服务, IsInitiating属性默认为true,因此每次调用时都从一个新实例开始。

SessionMode = SessionMode.Required 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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