2015-11-02 86 views
0

當我調用SOAP方法時,在C#中它返回null,但在Fiddler中,我看到實際上服務器返回一些數據。 WSDL的服務引用的方法返回null

片段:

<xsd:element name="GetRulesResponse"> 
    <xsd:complexType> 
     <xsd:sequence> 
      <xsd:element name="rules" type="tns:ArrayOfRulesType"/> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 

<xsd:complexType name="ArrayOfRulesType"> 
    <xsd:sequence> 
     <xsd:element name="rule" type="tns:RulesType" maxOccurs="unbounded" minOccurs="0"/> 
    </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="RulesType"> 
    <xsd:sequence> 
     <xsd:element name="field1" type="xsd:string"/> 
     <xsd:element name="field2" type="xsd:string"/> 
     <xsd:element name="field3" type="xsd:long"/> 
    </xsd:sequence> 
</xsd:complexType> 

實際的服務器響應:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gam="http://some.url/"> 
    <soap:Body> 
     <gam:GetRulesResponse> 
      <rule> 
       <gam:field1>sss</gam:field1> 
       <gam:field2>sss</gam:field2> 
       <gam:field3>100</gam:field3> 
      </rule> 
     </gam:GetRulesResponse> 
    </soap:Body> 
</soap:Envelope> 

C#生成的代碼:

[System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] 
    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfRulesType", Namespace="http://some.url", ItemName="rule")] 
    [System.SerializableAttribute()] 
    public class ArrayOfRulesType : System.Collections.Generic.List<Namespaces.RulesType> { 
    } 

    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] 
    [System.Runtime.Serialization.DataContractAttribute(Name="RulesType", Namespace="http://some.url")] 
    [System.SerializableAttribute()] 
    public partial class RulesType : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged { 

     [System.NonSerializedAttribute()] 
     private System.Runtime.Serialization.ExtensionDataObject extensionDataField; 

     private string field1Field; 

     private string field2Field; 

     private long field3Field; 


     [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, EmitDefaultValue=false)] 
     public string field1 { 
      get { 
       return this.field1Field; 
      } 
      set { 
       if ((object.ReferenceEquals(this.field1Field, value) != true)) { 
        this.field1Field= value; 
        this.RaisePropertyChanged("field1"); 
       } 
      } 
     } 

     [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, EmitDefaultValue=false)] 
     public string field2 { 
      get { 
       return this.field2Field; 
      } 
      set { 
       if ((object.ReferenceEquals(this.field2Field, value) != true)) { 
        this.field2Field = value; 
        this.RaisePropertyChanged("field2"); 
       } 
      } 
     } 

     [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, Order=2)] 
     public long field3 { 
      get { 
       return this.field3Field; 
      } 
      set { 
       if ((this.field3Field.Equals(value) != true)) { 
        this.field3Field = value; 
        this.RaisePropertyChanged("field3"); 
       } 
      } 
     } 

     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)); 
      } 
     } 
    } 




    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] 
    public partial class GetRulesResponse { 

     [System.ServiceModel.MessageBodyMemberAttribute(Name="GetRulesResponse", Namespace="http://some.url", Order=0)] 
     public Namespace.GetRulesResponseBody Body; 

     public GetRulesResponse() { 
     } 

     public GetRulesResponse(Namespace.GetRulesResponseBody Body) { 
      this.Body = Body; 
     } 
    } 

    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 
    [System.Runtime.Serialization.DataContractAttribute(Namespace="http://some.url")] 
    public partial class GetRulesResponseBody { 

     [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=0)] 
     public Namespace.ArrayOfRulesType rules; 

     public GetRulesResponseBody() { 
     } 

     public GetRulesResponseBody(Namespace.ArrayOfRulesType rules) { 
      this.rules = rules; 
     } 
    } 

這是一個第三方服務,所以我用不上來源。

我能做些什麼來解決它?

+1

你的C#代碼呢? – isxaker

+0

嘗試SOAP UI http://www.soapui.org/ –

+0

更新了生成的C#源代碼的問題。在SoapUI請求中工作正常。 –

回答

0

在解析期間收到響應時,檢查xml是否已被正確解析。如果不是那麼你得到空值。