小问题,当我在我的 Windows 机器上运行我的 ServiceStack API 应用程序时, namespace 正确显示,正如我所说的那样。但是当我在关闭 mod_mono 的 Linux 机器上运行该服务时。然后这些 namespace 被其他东西覆盖。请在下面查看我的代码:
数据传输
namespace API_ESERVICES_NOTIFICATION
{
[DataContract(Namespace = "urn:com.example:service:20130308")]
public class GetAccountNotification
{
[DataMember]
public GetAccountResponseTO getAccountResponse {
get;
set;
}
}
}
Windows 生成的 SOAP11 xml
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetAccountNotification xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:com.example:service:20130308">
<getAccountResponse xmlns:d2p1="urn:com.example:service:entity:20130308">
Linux 模式单声道
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetAccountNotification xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/API_ESERVICES_NOTIFICATION">
<getAccountResponse xmlns:d2p1="http://schemas.datacontract.org/2004/07/API_ESERVICES_NOTIFICATION.Model">
现在如何让 Linux 命名空间成为 urn:com.example:service:entity:20130308 和 urn:com.example:service:20130308,而不是 http://schemas.datacontract.org/2004/07/API_ESERVICES_NOTIFICATION.Model .任何帮助将不胜感激。
最佳答案
这看起来像是 Mono 中的一个错误,它没有选择 DataContract 的命名空间,或者没有考虑将 urn:
作为有效的 xml 命名空间前缀。我推荐filing a bug in Mono .
您可以尝试的替代方法是将命名空间留空并在项目的 Assembly.cs
中指定一个程序集属性,例如:
[assembly: ContractNamespace("urn:com.example:service:20130308",
ClrNamespace = "API_ESERVICES_NOTIFICATION")]
关于c# - ServiceStack 命名空间更改不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17542802/