我从SSRS向servicestack发出soap请求,无论我尝试什么,我都无法让Servicestack将任何东西识别为布尔值并反序列化。
[DataContract]
[Route("/Stuff")]
public class GetStuff : IReturn<GetStuffResponse>
{
[DataMember]
[ApiMember(Name = "Is Enabled",
DataType = "bool",
IsRequired = false)]
public bool? IsEnabled { get; set; }
}
传入的肥皂请求如下:
<?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>
我试图让肥皂请求发送&#34; 0&#34;和&#34; 1&#34;对于真/假,并且对于大写&#34; T&#34;是真的,但Servicestack总是将其反序列化为&#39; null&#39;。
有人有任何建议吗?
修改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; }
}
以下是发送到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>
现在这里变得奇怪,两个日期和#39;符号&#39;字段反序列化正确。电子邮件&#39;字段和&#39; IsEnabled&#39;字段失败并且为空。有没有办法跟踪Serivcestack中的Deserializer?
答案 0 :(得分:1)
ServiceStack没有使用它自己的XML Serializer,它使用.NET的WCF <?php
$email = $_POST["email"];
echo $email;
?>
类和.NET的Xml DataContract Serializer来序列化/反序列化SOAP请求。
WCF的SOAP非常严格/脆弱,因此您需要准确捕获发送的内容,以了解要发送的正确SOAP / XML。最简单的方法是使用Soap12ServiceClient发送您的请求DTO和像Fiddler这样的数据包嗅探器来捕获发送的原始HTTP请求主体,例如:
Message
发送SOAP请求:
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中很重要。