Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# web服务请求返回null_C#_.net_Web Services - Fatal编程技术网

C# web服务请求返回null

C# web服务请求返回null,c#,.net,web-services,C#,.net,Web Services,我试图调用一个托管在java服务器上的web服务。我已经通过VisualStudio提供的web服务创建工具创建了这些类。当我调用该方法时,我可以在Fiddler中看到它正在返回有效数据。然而,在我的C代码中,我的结果是空的 任何帮助都将不胜感激 C#呼叫代码: RuleValidationResponseRule[] ruleResponse = rulesWebService.RuleValidation(ruleData, "LO"); Web服务生成的代码: [System.Web.S

我试图调用一个托管在java服务器上的web服务。我已经通过VisualStudio提供的web服务创建工具创建了这些类。当我调用该方法时,我可以在Fiddler中看到它正在返回有效数据。然而,在我的C代码中,我的结果是空的

任何帮助都将不胜感激

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]));
}
/// <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;
        }
    }
}
传递到Web服务的XML(来自Fiddler):


从服务返回的XML(来自Fiddler):


C#生成代码中的响应定义:

[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]));
}
/// <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;
        }
    }
}
//
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.17929”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://www.example.org/LathamInt/")]
公共部分类RuleValidationResponseRule{
private RuleValidationResponseUroleExpression表达式字段;
私有字符串结果字段;
私有字符串规则字段;
私有字符串状态字段;
/// 
[System.Xml.Serialization.xmlementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public RuleValidationResponseUroleExpression表达式{
得到{
返回此.expressionField;
}
设置{
this.expressionField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute()]
公共字符串结果{
得到{
返回此.resultField;
}
设置{
this.resultField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute()]
公共字符串规则ID{
得到{
返回此.ruleIdField;
}
设置{
this.ruleIdField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute()]
公共字符串状态{
得到{
返回此.status字段;
}
设置{
this.statusField=值;
}
}
}

我相信我已经解决了这个问题

在返回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/", 

响应空间=”http://www.example.org/LathamInt/“,//我相信我已经解决了

在返回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/", 

响应空间=”http://www.example.org/LathamInt/",//这是很多代码。也许您可以通过中断代码、逐步执行代码并告诉我们数据在何处消失为null来帮助我们解决问题。我们将无法设置计算机来检查此问题,因此您可以更好地进行故障排除。但是,我同意Visual Studio似乎没有在生成的web服务代码。因此,我一直在试图理解生成的代码,以查看名称空间是否不合适或类似情况。然后放入一些日志语句。这行代码如下:object[]results=This.Invoke(“RuleValidation”,新对象[]{ruleData,company});显示结果有1个元素,该元素为null。我不太理解这行代码…它正在调用自己吗?这是很多代码。也许您可以通过中断代码,逐步遍历代码,并告诉我们数据在哪里消失为null来帮我们一点忙。我们无法设置机器来检查这一点,所以您可以更好地进行故障排除。但是,我同意,Visual Studio似乎没有破坏生成的web服务代码。因此,我一直在尝试理解生成的代码,以查看名称空间是否不合适或类似情况。然后输入一些日志语句。这一行:object[]results=This.Invoke(“RuleValidation”,新对象[]{ruleData,company});显示结果有1个元素,该元素为空。我不太理解这行代码…它是否在调用自身?1.将[]替换为[]在Reference.cs中-选中2.使用Web引用而不是服务引用-选中3.花半天搜索解决方案-选中4.阅读10多篇提到Axis/Java和.NET集成的文章-选中5.找到此响应和工作解决方案-选中:)谢谢!1.将[]替换为[]在Reference.cs中-选中2.使用Web引用而不是服务引用-选中3.花了半天时间搜索解决方案-选中4.阅读10多篇提到Axis/Java和.NET集成的文章-选中5.找到此响应和工作解决方案-选中:)谢谢!