Можно получить только первый результат от службы мыла Perl - PullRequest
1 голос
/ 03 августа 2011

Я пытаюсь использовать службу мыла 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 голосов
/ 04 августа 2011

решаемая.Была "фича" в мыле :: lite.вместо того, чтобы возвращать массив с

return @result

(это приведет к неправильному ответу мыла с параметрами вместо массива результатов), вам нужно сделать:и теперь все работает из коробки с автоматически сгенерированным кодом wsdl.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...