只能从perl soap服务获得第一个结果

时间:2011-08-03 08:14:57

标签: c# perl soap

我正在尝试使用perl肥皂服务:

=begin WSDL

_IN nr $string hah
_RETURN @string hih

=cut

所以perl接受一个参数并返回一个结果数组:

http://img29.imageshack.us/img29/1898/sniffer.png (点击查看完整尺寸的图片)

wsdl看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<!-- WSDL for http://10.0.252.24/VM created by Pod::WSDL version: 0.061 on Wed Aug  3 10:05:50 2011 -->
<wsdl:definitions targetNamespace="http://10.0.252.24/VM" xmlns:impl="http://10.0.252.24/VM" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns1="http://10.0.252.24/VM">

        <wsdl:types>
                <schema targetNamespace="http://10.0.252.24/VM" xmlns="http://www.w3.org/2001/XMLSchema">
                        <import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
                        <complexType name="ArrayOfString">
                                <complexContent>
                                        <restriction base="soapenc:Array">
                                                <attribute ref="soapenc:arrayType" wsdl:arrayType="soapenc:string[]" />
                                        </restriction>
                                </complexContent>
                        </complexType>
                </schema>
        </wsdl:types>

        <wsdl:message name="VMsRequest">
                <wsdl:part name="nr" type="xsd:string">
                        <wsdl:documentation>hah</wsdl:documentation>
                </wsdl:part>
        </wsdl:message>

        <wsdl:message name="VMsResponse">
                <wsdl:part name="VMsReturn" type="tns1:ArrayOfString">
                        <wsdl:documentation>hih</wsdl:documentation>
                </wsdl:part>
        </wsdl:message>

        <wsdl:portType name="VMHandler">
                <wsdl:operation name="VMs" parameterOrder="nr">
                        <wsdl:input message="impl:VMsRequest" name="VMsRequest" />
                        <wsdl:output message="impl:VMsResponse" name="VMsResponse" />
                </wsdl:operation>

        </wsdl:portType>

        <wsdl:binding name="VMSoapBinding" type="impl:VMHandler">
                <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />

                <wsdl:operation name="VMs">
                        <wsdlsoap:operation soapAction="" />
                        <wsdl:input name="VMsRequest">
                                <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://10.0.252.24/VM" use="encoded" />
                        </wsdl:input>
                        <wsdl:output name="VMsResponse">
                                <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://10.0.252.24/VM" use="encoded" />
                        </wsdl:output>
                </wsdl:operation>

        </wsdl:binding>

        <wsdl:service name="VMHandlerService">
                <wsdl:port binding="impl:VMSoapBinding" name="VM">
                        <wsdlsoap:address location="http://10.0.252.24/VM" />
                </wsdl:port>
        </wsdl:service>

</wsdl:definitions>

c#看起来像这样:

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;


[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="VMSoapBinding", Namespace="http://10.0.252.24/VM")]
public partial class VMHandlerService : System.Web.Services.Protocols.SoapHttpClientProtocol {

    private System.Threading.SendOrPostCallback VMsOperationCompleted;

    public VMHandlerService() {
        this.Url = "http://10.0.252.24/VM";
    }

    public event VMsCompletedEventHandler VMsCompleted;

    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://10.0.252.24/VM", ResponseNamespace="http://10.0.252.24/VM")]
    [return: System.Xml.Serialization.SoapElementAttribute("VMsReturn")]
    public string[] VMs(string nr) {
        object[] results = this.Invoke("VMs", new object[] {
                    nr});
        return ((string[])(results[0]));
    }

    public System.IAsyncResult BeginVMs(string nr, System.AsyncCallback callback, object asyncState) {
        return this.BeginInvoke("VMs", new object[] {
                    nr}, callback, asyncState);
    }

    public string[] EndVMs(System.IAsyncResult asyncResult) {
        object[] results = this.EndInvoke(asyncResult);
        return ((string[])(results[0]));
    }

    public void VMsAsync(string nr) {
        this.VMsAsync(nr, null);
    }

    public void VMsAsync(string nr, object userState) {
        if ((this.VMsOperationCompleted == null)) {
            this.VMsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnVMsOperationCompleted);
        }
        this.InvokeAsync("VMs", new object[] {
                    nr}, this.VMsOperationCompleted, userState);
    }

    private void OnVMsOperationCompleted(object arg) {
        if ((this.VMsCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.VMsCompleted(this, new VMsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }

    public new void CancelAsync(object userState) {
        base.CancelAsync(userState);
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void VMsCompletedEventHandler(object sender, VMsCompletedEventArgs e);

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class VMsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

    private object[] results;

    internal VMsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
            base(exception, cancelled, userState) {
        this.results = results;
    }

    /// <remarks/>
    public string[] Result {
        get {
            this.RaiseExceptionIfNecessary();
            return ((string[])(this.results[0]));
        }
    }
}

测试时:

string[] test = kk.VMs("35294000");

我得到一个例外:cannot convert string to string[]。 所以我将代码更改为:

    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace = "http://10.0.252.24/VM", ResponseNamespace = "http://10.0.252.24/VM")]
    [return: System.Xml.Serialization.SoapElementAttribute("VMsReturn")]
    public string VMs(string nr) {
        object[] results = this.Invoke("VMs", new object[] {
                    nr});
        return ((string)(results[0]));
    }

and
string test = kk.VMs("35294000");

现在返回结果。 但只有第一个结果,我应该得到一个数组。

1 个答案:

答案 0 :(得分:0)

解决。是soap :: lite中的“功能”。 而不是使用

返回数组
return @result

(这将返回带参数的错误soap回答而不是结果数组) 你需要这样做:

return \@result

将返回一个soap数组,现在一切都是开箱即用的自动生成的wsdl代码。