我正在尝试使用WCF客户端与Web服务进行通信。我没有/可以访问服务端,它是第三方。
以下是我遇到的问题:服务期望:
<OTAX_PkgBookRQ PrimaryLangID="en" ActionType="Hold" Version="0" TransactionIdentifier="c4ca204f-754c-4de2-b28d-107c2a23322e" xmlns="http://api.codegen.net/ota/tbx">
<PackageRequest ID="0">
<UniqueID Type="User" ID="10344"></UniqueID>
<UniqueID Type="Customer" ID="15489"></UniqueID>
<ItineraryItems xmlns="http://api.codegen.net/ota/tbx">
<ItineraryItem SwapItemNo="0" ItemNo="0" RPH="0:0">
<ItemDetail>
<Flight>
<FlightSegments>
<FlightSegment RPH="0:0"></FlightSegment>
<FlightSegment RPH="1:0"></FlightSegment>
</FlightSegments>
</Flight>
</ItemDetail>
</ItineraryItem>
但是我的WCF客户端发送了这个:
<OTAX_PkgBookRQ PrimaryLangID="en" ActionType="Hold" Version="0" TransactionIdentifier="c4ca204f-754c-4de2-b28d-107c2a23322e" xmlns="http://api.codegen.net/ota/tbx">
<PackageRequest ID="0">
<UniqueID Type="User" ID="10344"></UniqueID>
<UniqueID Type="Customer" ID="15489"></UniqueID>
<ItineraryItems>
<ItineraryItem SwapItemNo="0" ItemNo="0" RPH="0:0">
<ItemDetail>
<Flight>
<FlightSegments>
<FlightSegment RPH="0:0"></FlightSegment>
<FlightSegment RPH="1:0"></FlightSegment>
</FlightSegments>
</Flight>
</ItemDetail>
</ItineraryItem>
请注意<ItineraryItems>
节点
我非常确定名称空间被省略了#39;因为它是已在范围内的命名空间(来自<OTAX_PkgBookRQ>
节点)。我试图使用消息检查器修改节点,但XmlNode实例已经指定了正确的命名空间。
有没有办法可以强制WCF在特定节点上输出命名空间?
编辑:这可能会有所帮助
这是ItineraryItems的实际类型(来自reference.cs)
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.codegen.net/ota/tbx")]
public partial class PkgItineraryItemType : object, System.ComponentModel.INotifyPropertyChanged
这是内心的&#39;声明(来自reference.cs):
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Order=4)]
[System.Xml.Serialization.XmlArrayItemAttribute("ItineraryItem", IsNullable=false)]
public PkgItineraryItemType[] ItineraryItems {
get {
return this.itineraryItemsField;
}
set {
this.itineraryItemsField = value;
this.RaisePropertyChanged("ItineraryItems");
}
}
答案 0 :(得分:0)
将名称空间属性添加到下面的部分内部&#39;内部&#39;声明
[System.Xml.Serialization.XmlArrayItemAttribute(Namespace = "ttp://api.codegen.net/ota/tbx")]
例如,您的代码应如下所示
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(Order=4)]
[System.Xml.Serialization.XmlArrayItemAttribute("ItineraryItem", IsNullable=false)]
[System.Xml.Serialization.XmlArrayItemAttribute(Namespace = "http://api.codegen.net/ota/tbx")]
public PkgItineraryItemType[] ItineraryItems {
get {
return this.itineraryItemsField;
}
set {
this.itineraryItemsField = value;
this.RaisePropertyChanged("ItineraryItems");
}
}