我有一份WCF服务,可追溯到以下数据查询:
[DataContract] public class RequestWrapper { [DataMember] public FooDataContract FooDataContract; } [DataContract] public class ResponseWrapper { [DataMember] public FooDataContract FooDataContract; } [DataContract] public class FooDataContract { public FooDataContract(string data, Guid id) { Data = data; ID = id; } [DataMember] public string Data { get; set; } [DataMember] public Guid ID { get; set; } }
它通过代相传的一类:
void CallService(string data) { var id = Guid.NewGuid(); var response = proxy.CallService(new RequestWrapper { new FooDataContract(data, id); }); }
然后通过一个使用EF的存放处将这一服务转至数据库:
public void RepoMethod(FooDataContract foo) { var guid = foo.ID; // - Breakpoint here shows all zeros! efContext.DoSomething(foo.Data, foo.ID); }
这里的服务呼吁:
public ResponseWrapper CallService(RequestWrapper request) { var foo = request.FooDataContract; repository.RepoMethod(foo); var response = new ResponseWrapper{ FooDataContract = foo }; return response; }
代表:
public class Proxy : IMyService { static readonly ChannelFactory<IMyService> channelFactory = new ChannelFactory<IMyService>("IMyService"); ResponseWrapper CallService(RequestWrapper request) { return channelFactory.UseService(s => s.CallService(request)); } } internal static class UseServiceFunction { internal static R UseService<T, R> (this ChannelFactory<T> channelFactory, Func<T, R> useService) { var service = channelFactory.CreateChannel(); try { R response = useService(service); return response; } finally { var channel = service as ICommunicationObject; try { if (channel.State != CommunicationState.Faulted) channel.Close(); } catch { channel.Abort(); } } } }
我在VS debugger对《指南》进行了观察。 当服务从客户网络应用中调取时,所生成的《指南》是看似随机性质的有效指南。 说到底,这起作用。
但是,如果数据是按序排列的,就会接上电线,而另一方面(在我的存放处),则《指南》是零!
我翻了一番,三倍地检查了《指南》确实以[Data Member]属性为标志。 I m 想知道,额外的数据层(如何用“要求数据合同”对FooDataContract进行总结)是否造成了一个序列化问题?