ResponseStatus xmlns d2p1

The question arises: how to use one namespace for the answer when using the IHasResponseStatus and public ResponseStatus ResponseStatus { get; set; } properties public ResponseStatus ResponseStatus { get; set; } public ResponseStatus ResponseStatus { get; set; } public ResponseStatus ResponseStatus { get; set; } and remove the d2p1 prefix on ResponseStatus .

I use one http://schemas.tagway.com.ua/types namespace for all web service models; the answer looks great except for the node ResponseStatus because ServiceStack: it automatically adds its own xmlns:d2p1="http://schemas.servicestack.net/types" namespace xmlns:d2p1="http://schemas.servicestack.net/types" for ResponseStatus.

Service Model:

 namespace NTPCore.ServiceModel.Operations.Balance { public class Balance { public Auth auth { get; set; } } public class BalanceResponse : IHasResponseStatus { public ResponseStatus ResponseStatus { get; set; } public int balance { get; set; } public int limit { get; set; } } } 

AssemblyInfo.cs in the NTPCore.ServiceModel project:

 [assembly: ContractNamespace("http://schemas.tagway.com.ua/types", ClrNamespace = "NTPCore.ServiceModel.Operations.Balance")] [assembly: ContractNamespace("http://schemas.tagway.com.ua/types", ClrNamespace = "ServiceStack.ServiceInterface.ServiceModel")] //may be this not need...experimenting, nothing happance for me 

Answer example:

 <BalanceResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.tagway.com.ua/types"> <ResponseStatus xmlns:d2p1="http://schemas.servicestack.net/types"> <d2p1:ErrorCode>String</d2p1:ErrorCode> <d2p1:Errors> <d2p1:ResponseError> <d2p1:ErrorCode>String</d2p1:ErrorCode> <d2p1:FieldName>String</d2p1:FieldName> <d2p1:Message>String</d2p1:Message> </d2p1:ResponseError> </d2p1:Errors> <d2p1:Message>String</d2p1:Message> <d2p1:StackTrace>String</d2p1:StackTrace> </ResponseStatus> <balance>0</balance> <limit>0</limit> </BalanceResponse> 
+4
source share
2 answers

ServiceStack uses the built-in XML DataContractSerializer.NET for its XML serialization. Unfortunately, for the [assembly: ContractNamespace ..] effect, you need to decorate your DTO with the attributes [DataContract] and [DataMember] . eg:

 [DataContract] public class Balance { [DataMember] public Auth auth { get; set; } } [DataContract] public class BalanceResponse : IHasResponseStatus { [DataMember] public ResponseStatus ResponseStatus { get; set; } [DataMember] public int balance { get; set; } [DataMember] public int limit { get; set; } } 

It's ugly, but to pay for pretty XML, another option is to override the embedded XML Content-Type with your own Serialization / Deserialization procedures - but it takes more work.

+2
source
 [CollectionDataContract(Name = "root", ItemName = "row")] 
0
source

All Articles