【发布时间】:2019-04-19 13:06:46
【问题描述】:
我正在尝试使用 SOAP 通过 http POST 请求向我发送消息的远程服务。我使用集成在 Visual Studio 中的选项“添加服务引用”生成了服务 DTO。
这是一个自动生成的类的示例:
[Route("/test", "POST")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
Namespace="http://www.reservationassistant.com/Booking/Types")]
public partial class UpdateBookingRequest
{
private Booking bookingField;
private string resortIdField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public Booking Booking
{
get
{
return this.bookingField;
}
set
{
this.bookingField = value;
}
}
当我创建我的 ServiceInterface 方法并运行我的服务时,进入元数据页面我会得到这个示例 SOAP 消息
<UpdateBookingRequest>
<bookingField>
....
<bookingField>
<UpdateBookingRequest>
这是我的服务接口类中的代码:
UpdateBookingResponse Post(UpdateBookingRequest request)
{
// do stuff with request
return null;
}
正如您可能通过自动生成的类所暗示的那样,我收到的消息将具有与生成的 DTO 中的公共属性相同的标记名称。然而,这永远不可能,因为出于某种原因,ServiceStack 试图将传入的 XML 消息元素绑定到 DTO 的私有字段(由我的服务的元数据页面生成的示例 SOAP 消息 - 请注意“预订”之后的“字段”后缀”)。如何使传入消息绑定到公共属性而不是私有字段?
【问题讨论】:
标签: c# xml soap servicestack