Can only get first result from perl soap service
I'm trying to consume a perl soap service:
=begin WSDL
_IN nr $string hah
_RETURN @string hih
=cut
so the perl takes one argument and returns an array of results:
http://img29.imageshack.us/img29/1898/sniffer.png (click to view full sized image)
the wsdl looks like this:
<?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>
And the c# looks like this:
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]));
}
}
}
When testing:
string[] test = kk.VMs("35294000");
I get an exception: cannot convert string to string[]
.
So I change the code to:
[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");
It now returns a result. But only the first result and I should get an array.
Solved. Was a "feature" in soap::lite. instead of returning an array with
return @result
(This will return wrong soap answer with parameters instead of a result array) you need to do:
return \@result
which will return a soap array and now everything works out of the box with the auto-generated wsdl code.
精彩评论