我从Web服务收到以下SOAP响应。
<soap:Body>
<SubscriptionQueryResponse>
<Subscriptions>
<Subscription></Subscription>
<Subscription></Subscription>
</Subscriptions>
<TotalCount>2</TotalCount>
<ResultCount>2</ResultCount>
<StartingSequence>0</StartingSequence>
</SubscriptionQueryResponse>
</soap:Body>
我需要获得总计数。
以下是我的代码:
[SoapDocumentMethod( "&&&", RequestElementName = "SubscriptionQueryRequest", RequestNamespace = "&&&", ResponseNamespace = "&&&", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped )]
[return: XmlArray("Subscriptions")]
[return: XmlArrayItem("Subscription", IsNullable = false)]
public Subscription[] SubscriptionQuery(string SubscriberId, int SortType, bool SortDescending, string Service, string ReferenceID, string SubscriptionName, int StartingSequence, int ResultCount )
{
object[] results = this.Invoke( "SubscriptionQuery", new object[] {
SubscriberId,
SortType,
SortDescending,
Service,
ReferenceID,
SubscriptionName,
StartingSequence,
ResultCount
} );
return ( (Subscription[])( results[0] ) );
}
如您所见,我已经返回了订阅。订阅列表位于返回数组的索引0中。我还想将Total Count作为返回数组的索引1返回,但返回XmlArray语句只返回订阅并自动转换它们。
编辑:至少,我希望原始XML没有它序列化它,我可以自己解析它。
注意:忽略&#34;&amp;&amp;&amp;&#34;在SoapDocumentMethod中。我删除了他们的显示值。
答案 0 :(得分:0)
我的问题的解决方案是没有框架序列化xml。
[SoapDocumentMethod( "&&&", RequestElementName = "SubscriptionQueryRequest", RequestNamespace = "&&&", ResponseNamespace = "&&&", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped )]
[return: XmlAnyElement]
public List<XmlNode> SubscriptionQuery(string SubscriberId, int SortType, bool SortDescending, string Service, string ReferenceID, string SubscriptionName, int StartingSequence, int ResultCount )
{
object[] results = this.Invoke( "SubscriptionQuery", new object[] {
SubscriberId,
SortType,
SortDescending,
Service,
ReferenceID,
SubscriptionName,
StartingSequence,
ResultCount
} );
return ( (List<XmlNode>)( results[0] ) );
}
这会将响应中的所有节点转换为列表,然后我可以在响应中获取我想要的每个单独节点并自行反序列化它们,而不是让框架执行它。