只能从perl soap服务中获得第一个结果
本文关键字:第一个 结果 服务 perl soap | 更新日期: 2023-09-27 18:04:25
我正在尝试使用perl soap服务:
=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");
现在返回一个结果。但只有第一个结果,我应该得到一个数组
解决。是soap:: life中的一个"特性"。而不是返回带有
的数组return @result
(这将返回带有参数而不是结果数组的错误soap答案)你需要做的是:
return '@result
,它将返回一个soap数组,现在一切都可以使用自动生成的WSDL代码开箱即用了。