详细信息:
接口(interface)契约:
[OperationContract]
[WebGet(UriTemplate = "test")]
TestType TestOperation();
类型定义:
[System.Xml.Serialization.XmlRoot(ElementName = "Test", Namespace="http://test.net/", IsNullable=false)]
public partial class TestType {
实际结果:
<TestType xmlns=http://schemas.datacontract.org/2004/07/ …
预期结果:
<Test xmlns= http://test.net/ …
请指教。
最佳答案
该服务正在使用 DataContractSerializer
来序列化响应,因此需要数据协定命名空间。为了覆盖它,我建议将 XmlSerialzeFormat 属性应用于操作,如下所示...
[OperationContract]
[WebGet(UriTemplate = "test")]
[XmlSerializerFormat]
TestType TestOperation();
关于c# - .Net Rest Web 服务响应具有默认的数据协定命名空间而不是预期的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18256550/