質問

Details:

Interface Contract:

[OperationContract]
[WebGet(UriTemplate = "test")]
TestType TestOperation();

Type Definition:

[System.Xml.Serialization.XmlRoot(ElementName = "Test", Namespace="http://test.net/", IsNullable=false)]
public partial class TestType {

Actual Result:

<TestType xmlns=http://schemas.datacontract.org/2004/07/ …

Expected Result:

<Test xmlns= http://test.net/ …

Please advise.

役に立ちましたか?

解決

The service is using the DataContractSerializer to serialize the response and therefore requires the data contract namespace. In order to override that I would recommend applying the XmlSerialzeFormat Attribute to the operation as follows...

[OperationContract]
[WebGet(UriTemplate = "test")]
[XmlSerializerFormat]
TestType TestOperation();

他のヒント

If this is a WCF service, it uses data contract serializers by default. Try using data contract attributes to decorate your class instead:

[DataContract(Name = "Test", Namespace="http://test.net/")]
public partial class TestType {

Note: you'll also need to add DataMember attributes to each field or property that you want serialized.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top