2012-10-25 166 views
0

我正在嘗試調用託管在Java服務器上的Web服務。我通過Visual Studio提供的Web服務創建工具創建了這些類。當我調用該方法時,我可以在Fiddler中看到它正在返回有效數據。但是,在我的C#代碼中,我的結果爲空。Web服務請求返回null

任何幫助,將不勝感激。

C#調用代碼:

RuleValidationResponseRule[] ruleResponse = rulesWebService.RuleValidation(ruleData, "LO"); 

Web服務生成的代碼:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.example.org/LathamInt/RuleValidation", 
    RequestNamespace="http://www.example.org/LathamInt/", 
    ResponseNamespace="http://www.example.org/LathamInt/", 
    Use=System.Web.Services.Description.SoapBindingUse.Literal, 
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 
[return: System.Xml.Serialization.XmlArrayAttribute("ruleValidationResp", 
    Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
[return: System.Xml.Serialization.XmlArrayItemAttribute("rule", 
    Form=System.Xml.Schema.XmlSchemaForm.Unqualified, 
    IsNullable=false)] 
public RuleValidationResponseRule[] RuleValidation([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    RuleValidationRuleData ruleData, 
    [System.Xml.Serialization.XmlAttributeAttribute()] string company) { 
    object[] results = this.Invoke("RuleValidation", new object[] { 
       ruleData, 
       company}); 
    return ((RuleValidationResponseRule[])(results[0])); 
} 

XML傳遞給web服務(從小提琴手):

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <RuleValidation company="LO" xmlns="http://www.example.org/LathamInt/"> 
      <ruleData xmlns=""> 
       <rule ruleID="GDSP" /> 
       <varData varName="GuideSpace" varValue="3" /> 
      </ruleData> 
     </RuleValidation> 
    </soap:Body> 
</soap:Envelope> 

XML從服務返回(來自Fiddler):

在C#

響應定義生成的代碼:

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.example.org/LathamInt/")] 
public partial class RuleValidationResponseRule { 

    private RuleValidationResponseRuleExpression expressionField; 

    private string resultField; 

    private string ruleIdField; 

    private string statusField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public RuleValidationResponseRuleExpression expression { 
     get { 
      return this.expressionField; 
     } 
     set { 
      this.expressionField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string result { 
     get { 
      return this.resultField; 
     } 
     set { 
      this.resultField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string ruleId { 
     get { 
      return this.ruleIdField; 
     } 
     set { 
      this.ruleIdField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public string status { 
     get { 
      return this.statusField; 
     } 
     set { 
      this.statusField = value; 
     } 
    } 
} 
+0

這是一個很大的代碼。也許你可以通過突出代碼,逐步完成代碼並告訴我們數據在哪裏消失爲空來幫助我們。我們無法設置一臺機器來檢查這一點,因此您可以更好地排除故障。 –

+0

但是,我同意Visual Studio在生成的Web服務代碼中似乎沒有中斷。所以我堅持試圖理解生成的代碼,看看命名空間是不是地方或類似的東西。 – Scottie

+0

然後放入一些日誌語句。 –

回答

3

我相信我已經解決了它。

在返回XML,這條線

<RuleValidationResponse> 

意味着返回標籤沒有命名空間。它需要改變

<lat:RuleValidationResponse> 

要麼,或修改線路

[System.Web.Services.Protocols.SoapDocumentMethodAttribute ("http://www.example.org/LathamInt/RuleValidation", 
    RequestNamespace="http://www.example.org/LathamInt/", 
    ResponseNamespace="http://www.example.org/LathamInt/", //<-- ** Change this line 
    Use=System.Web.Services.Description.SoapBindingUse.Literal, 
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 

[System.Web.Services.Protocols.SoapDocumentMethodAttribute ("http://www.example.org/LathamInt/RuleValidation", 
    RequestNamespace="http://www.example.org/LathamInt/", 
    ResponseNamespace="", //<-- ** Change this line 
    Use=System.Web.Services.Description.SoapBindingUse.Literal, 
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]