自动生成的Soap客户端无法解析响应

时间:2017-11-23 21:51:20

标签: c# .net web-services wcf soap

我在我的一个项目中添加了一个ServiceReference,不确定这个服务是否是在.net中进行的,当我对其中一个操作执行调用时,我得到一个包含1个元素的对象数组,这个元素已经满了空值,我已经用fiddler检查过,数据响应正确。你们知道为什么会这样吗?

SoapResponse结构:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <searchOrderResponse xmlns="http://xml.comcast.com/nationalaccountsportal/services">
         <searchOrderReturn>
            <ns1:searchResult xsi:type="ns1:OrderDetails" xmlns:ns1="http://xml.comcast.com/nationalaccountsportal/types"> <!-- The data -->
            <ns2:searchResult xsi:type="ns2:OrderDetails" xmlns:ns2="http://xml.comcast.com/nationalaccountsportal/types">

自动生成的类定义:

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(WrapperName="searchOrderResponse", WrapperNamespace="http://xml.comcast.com/nationalaccountsportal/services", IsWrapped=true)]
    internal partial class searchOrderResponse {

        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://xml.comcast.com/nationalaccountsportal/services", Order=0)]
        [System.Xml.Serialization.XmlElementAttribute("searchOrderReturn")]
        public OrderDetails[] searchOrderReturn;

        public searchOrderResponse() {
        }

        public searchOrderResponse(OrderDetails[] searchOrderReturn) {
            this.searchOrderReturn = searchOrderReturn;
        }
    }

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1590.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://xml.comcast.com/nationalaccountsportal/types")]
    public partial class OrderDetails : object, System.ComponentModel.INotifyPropertyChanged {

WSDL中的searchOrderResponse定义:

<element name="searchOrderResponse">
        <complexType>
          <sequence>
            <element maxOccurs="unbounded" name="searchOrderReturn" type="tns1:OrderDetails"/>
          </sequence>
        </complexType>
      </element>

谢谢!

1 个答案:

答案 0 :(得分:0)

我忘了更新你们,问题是WSDL错误地描述了响应,导致VS生成错误的代码,缺少其中一个标记或VS生成&#39; em&#34 ;的responseType&#34;所以我补充说:

/* Portrait and Landscape */
@media only screen 
  and (min-device-width: 1024px) 
  and (max-device-width: 1366px) 
  and (-webkit-min-device-pixel-ratio: 1.5) {
}

/* Portrait */
@media only screen 
  and (min-device-width: 1024px) 
  and (max-device-width: 1366px) 
  and (orientation: portrait) 
  and (-webkit-min-device-pixel-ratio: 1.5) {
}

/* Landscape */
@media only screen 
  and (min-device-width: 1024px) 
  and (max-device-width: 1366px) 
  and (orientation: landscape) 
  and (-webkit-min-device-pixel-ratio: 1.5) {

}

请注意,该属性称为searchResult,如上面的Response结构中,类的名称可以不同,但​​我将其保留为SearchOrderResponseType,因为它是VS如何命名的。在此之后,您必须更改Response类中的返回类型,如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1590.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xml.comcast.com/nationalaccountsportal/types")]
public partial class SearchOrderResponseType : object, System.ComponentModel.INotifyPropertyChanged
{

    private OrderDetails[] searchResultField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public OrderDetails[] searchResult
    {
        get
        {
            return this.searchResultField;
        }
        set
        {
            this.searchResultField = value;
            this.RaisePropertyChanged("searchResult");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null))
        {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

所以,基本上,这只是一个缺少的课程,希望这有帮助