问题是:如何使用一个命名空间进行响应,在使用IHasResponseStatus
和public ResponseStatus ResponseStatus { get; set; }
属性时,并删除前缀 d2p1 on ResponseStatus
。
http://schemas.tagway.com.ua/types
我为所有 Web 服务模型使用一个命名空间;响应看起来不错,除了节点 ResponseStatus,因为 ServiceStack:它会自动为 ResponseStatus 添加自己的命名空间xmlns:d2p1="http://schemas.servicestack.net/types"
。
服务模式:
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; }
}
}
NTPCore.ServiceModel 项目中的 AssemblyInfo.cs:
[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
示例响应:
<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>