使用 DCS 进行 MessageContract 序列化
有没有办法让 DataContractSerializer 序列化 [MessageContract]
与通过 SOAP 传输时的显示方式相同?
我有一个类在 WCF 调用中显示如下: <代码>
<TestRequest xmlns="http://webservices.test.com/ServiceTest/1.1">
<Name>Just Me</Name>
</TestRequest>
当使用DCS进行序列化时,它看起来像这样: <代码>
<TestRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/ServiceTest">
<_x003C_Name_x003E_k__BackingField z:Id="2">Just Me</_x003C_Name_x003E_k__BackingField>
</TestRequest>
我确信这种不一致是因为我的类被标记为消息契约而不是数据契约: <代码>
[MessageContract]
[Serializable]
public class TestRequest
{
[MessageBodyMember]
public string Name { get; set; }
}
有没有办法让 DCS 序列化消息,就像 WCF 创建 SOAP 消息时那样?
Is there a way to make the DataContractSerializer serialize a [MessageContract]
the same way it appears when transmitted over SOAP?
I have a class that appears as follows on the wire for a WCF call:
<TestRequest xmlns="http://webservices.test.com/ServiceTest/1.1"> <Name>Just Me</Name> </TestRequest>
When serializing using the DCS, it looks like this:
<TestRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/ServiceTest"> <_x003C_Name_x003E_k__BackingField z:Id="2">Just Me</_x003C_Name_x003E_k__BackingField> </TestRequest>
I'm convinced this inconsistency is because my class is marked up as a message contract instead of a data contract:
[MessageContract] [Serializable] public class TestRequest { [MessageBodyMember] public string Name { get; set; } }
Is there a way to make the DCS serialize messages the same way WCF does when it creates a SOAP message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您正在寻找数据合同代理。顺便说一句,您可以使用 DataContractSerializer 的构造函数来设置命名空间和根名称。
I guess you are looking for Data Contract Surrogates. BTW you can use the DataContractSerializer's constructor to set the namespace and root name.