使用Servicestack从Soap反序列化布尔值
我正在从SSRS向servicestack发出一个soap请求,无论我做什么尝试,我都无法让servicestack将任何内容识别为布尔值并对其进行反序列化使用Servicestack从Soap反序列化布尔值,soap,servicestack,Soap,servicestack,我正在从SSRS向servicestack发出一个soap请求,无论我做什么尝试,我都无法让servicestack将任何内容识别为布尔值并对其进行反序列化 [DataContract] [Route("/Stuff")] public class GetStuff : IReturn<GetStuffResponse> { [DataMember] [ApiMember(Name = "Is Enabled", DataType = "bool",
[DataContract]
[Route("/Stuff")]
public class GetStuff : IReturn<GetStuffResponse>
{
[DataMember]
[ApiMember(Name = "Is Enabled",
DataType = "bool",
IsRequired = false)]
public bool? IsEnabled { get; set; }
}
[DataContract]
[路线(“/Stuff”)]
公共类GetStuff:IReturn
{
[数据成员]
[ApiMember(Name=“已启用”,
DataType=“bool”,
IsRequired=false)]
公共布尔?IsEnabled{get;set;}
}
传入的soap请求如下所示:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetStuff xmlns="http://www.myCompany.com/types">
<IsEnabled>true</IsEnabled>
</GetTradesGroupedByClient>
</soap:Body>
</soap:Envelope>
真的
我已经尝试让soap请求发送“0”和“1”表示真/假,并使用大写字母“T”表示真,但Servicestack总是将其反序列化为“null”
有人有什么建议吗
编辑1
进一步的陌生更新。我用int替换了bool,希望这不会太麻烦,但是这也没有反序列化。因此,我在请求中添加了一些字段,以查看是否所有反序列化都会失败:
[DataContract]
[Route("/Stuff")]
public class GetStuff : IReturn<GetStuffResponse>
{
[DataMember]
[ApiMember(Name = "Summary Date",
DataType = "DateTime",
IsRequired = false)]
public DateTime? SummaryDate { get; set; }
[DataMember]
[ApiMember(Name = "Summary End Date",
DataType = "DateTime",
IsRequired = false)]
public DateTime? SummaryEndDate { get; set; }
[DataMember]
[ApiMember(Name = "Symbol",
DataType = "string",
IsRequired = false)]
public string Symbol { get; set; }
[DataMember]
[ApiMember(Name = "Email",
DataType = "string",
IsRequired = false)]
public string Email { get; set; }
[DataMember]
[ApiMember(Name = "Is Enabled",
DataType = "int",
IsRequired = false)]
public int? IsEnabled { get; set; }
}
[DataContract]
[路线(“/Stuff”)]
公共类GetStuff:IReturn
{
[数据成员]
[ApiMember(Name=“摘要日期”,
DataType=“DateTime”,
IsRequired=false)]
公共日期时间?SummaryDate{get;set;}
[数据成员]
[ApiMember(Name=“摘要结束日期”,
DataType=“DateTime”,
IsRequired=false)]
公共日期时间?SummaryEndDate{get;set;}
[数据成员]
[ApiMember(Name=“Symbol”,
DataType=“string”,
IsRequired=false)]
公共字符串符号{get;set;}
[数据成员]
[ApiMember(Name=“Email”,
DataType=“string”,
IsRequired=false)]
公共字符串电子邮件{get;set;}
[数据成员]
[ApiMember(Name=“已启用”,
DataType=“int”,
IsRequired=false)]
公共int?IsEnabled{get;set;}
}
以下是发送到serviceStack的soap:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetStuff xmlns="http://www.myCompany.com/types">
<SummaryDate>2018-04-26</SummaryDate>
<SummaryEndDate>2018-04-26</SummaryEndDate>
<Symbol>TOU</Symbol>
<Email>Guy.Smiley@myCompany.net</Email>
<IsEnabled>1</IsEnabled>
</GetStuff>
</soap:Body>
</soap:Envelope>
2018-04-26
2018-04-26
头
家伙。Smiley@myCompany.net
1.
现在这里是它变得奇怪的地方,两个日期和'symbol'字段反序列化正确。“电子邮件”字段和“IsEnabled”字段失败且为空。有什么方法可以跟踪SerivCastack中的反序列化程序吗?ServiceStack不使用自己的XML序列化程序,它使用.NET的WCF
消息
类和.NET的XML DataContract序列化程序来序列化/反序列化SOAP请求
WCF的SOAP非常严格/脆弱,因此您需要准确捕获所发送的内容,以了解要发送的正确SOAP/XML。最简单的方法是使用发送您的请求DTO和数据包嗅探器来捕获发送的原始HTTP请求正文,例如:
var client = new Soap12ServiceClient(baseUrl);
var request = new GetStuff {
SummaryDate = DateTime.Parse("2018-04-26"),
SummaryEndDate = DateTime.Parse("2018-04-26"),
Symbol = "TOU",
Email = "Guy.Smiley@myCompany.net",
IsEnabled = true,
};
var response = client.Send(request);
它发送SOAP请求:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">GetStuff</a:Action>
<a:MessageID>urn:uuid:5cb1b87c-82ae-422b-9b6a-3044eeb90fe7</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://test.servicestack.net/Soap12</a:To>
</s:Header>
<s:Body>
<GetStuff xmlns="http://schemas.servicestack.net/types" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Email>Guy.Smiley@myCompany.net</Email>
<IsEnabled>true</IsEnabled>
<SummaryDate>2018-04-26T00:00:00</SummaryDate>
<SummaryEndDate>2018-04-26T00:00:00</SummaryEndDate>
<Symbol>TOU</Symbol>
</GetStuff>
</s:Body>
</s:Envelope>
GetStuff
urn:uuid:5cb1b87c-82ae-422b-9b6a-3044eeb90fe7
http://www.w3.org/2005/08/addressing/anonymous
http://test.servicestack.net/Soap12
家伙。Smiley@myCompany.net
真的
2018-04-26T00:00:00
2018-04-26T00:00:00
头
请注意,属性的顺序是按字母顺序排列的,这在SOAP/XML中很重要 更真实的话是说不出来的:WCF的肥皂非常易碎!!!!我从来没有想过,基于xml的文档中参数的字母顺序会很重要!非常感谢您的见解。作为SSRS用户的后续操作,您可以在“数据集属性”对话框的“参数”选项卡中更改查询生成的参数顺序。手动使用向上/向下箭头按字母顺序排列。