English 中文(简体)
WCF 准则 未经适当编辑的数据成员
原标题:WCF Guid DataMember not Serialized properly

我有一份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进行总结)是否造成了一个序列化问题?

最佳回答

简而言之,我的翻译层已经更新,以便转换为DTOs! Who!

问题回答

我认为,你这里的问题是,你在数据查询表中所作的造物人没有被送到客户方面的代理人手中。 WSDL赢得了这方面的任何知识。 想把你的数据合同当作一个没有其他功能的固定数据的地方。 为了证实这一点,当你增加服务参考时,你可以看看客户生成的参考资料。

d 我建议重写该法典,以便你在数据合同中明确确定每一项价值,而不是依靠建筑商。

你还可以写出一部手写的代理书,它有你想要的任何行为,然后向客户分享。 这将奏效,但你会更紧密地把你的客户与你一起工作。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签