perl # 数组长度_如何将数组从Perl Soap :: Lite传递到C#Web服务

perl # 数组长度

我在执行此操作时遇到很多问题,因此,当我最终使它起作用时,我想我会分享财富。 我确实在尝试将文件从Perl脚本传递到C#Web服务,但是它从未起作用。 我所能做的最好的事情是将文件的内容作为数组传递,即使那也不是野餐。

因此,您需要安装Perl,然后安装Soap :: Lite软件包。 我正在AIX和Windows中工作。

像这样编写一个Perl脚本(myscript.pl):


# reference the Soap::Lite package and turn on tracing
use SOAP::Lite +trace=>all; 
#  read the file you want to send into an array
my $logFilename = 'myfile2.txt'; 
open(DATA,"<$logFilename") or die "Can't open data";
@lines = <DATA>;
close(DATA); 
#  Create the Soap::Lite client   
#  The "proxy" is the Dot Net asmx file you created in    Visual Studio for your web service
#  The "uri" is the location of the web service.  I created an IIS Web Site and set the path to the Visual Studio source code of the web service
#  The "on_action" method formats your soap request so Dot Net can read it 
my $client = SOAP::Lite->new();
$client->proxy('http://172.10.10.10/webservice/ErrorManager.asmx');
$client->uri('http://172.10.10.10/webservice');
$client->on_action(sub { join '/', @_ }); 
#  Compose a Perl array with the arguments to your web service method.  The names of the arguments must exactly match your web service ( including case ).  There were many posts suggesting other decorations such as soap-encoding, arrayType, and size, but I found I didn't need them. 
my @params = ( SOAP::Data->name('logFileName')->value($logFilename)->type('string'),  
     SOAP::Data->name('logArray')->value(\SOAP::Data->name('item' => @lines)->type('string'))
              ); 
#  Call your web service method and print the result 
$som = $client->ReportError(@params);
my $output = $som->result;
print $output . "\n"; 
但是,除非您调整Dot Net Web服务中的某些内容,否则所有这些仍然无法使用。

创建Web服务时,必须将名称空间设置为与上述uri相同的值:

[WebService(名称空间=“ http://172.10.10.10/webservice”)

如前所述,必须将Perl脚本中的参数命名为与Web服务方法中定义的参数完全相同的名称。 否则,参数将在您的Web服务中显示为null。 不正确的参数名称是错误的主要来源!

您必须在Web服务中使用“对象”类型定义数组参数变量。 进入您的网络服务后,您可以将其转换为

XML节点数组如下所示:


 Array array = arr as Array; 
 foreach (XmlNode node in array)
 {
   if (!WriteLogFile(node.InnerText)) break;
 }  
更糟糕的是,您需要使用[SoapRpcMethod]或[SoapDocumentMethod]装饰Web服务方法,无论哪种方法都可以! 我根本不理解这一点,因为如果我在AIX中运行Perl脚本,则需要[SoapRpcMethod],但是当我在Windows中运行相同的Perl脚本时,则需要[SoapDocumentMethod]。 它可能与每种环境中Perl软件包的级别有关,但我一无所知,既然可以正常工作,我就不在乎。

还有一项:要调试Dot Net Web服务,请打开该项目并进行构建,然后单击“调试”>“附加到进程”>“ aspnet_wp.exe”。 如果看不到aspnet_wp.exe,请在服务器上打开一个网页以启动该过程。 然后执行您的Perl脚本(在Aix或Windows中)> perl myscript.pl,Visual Studio应该在您的断点处停止!

翻译自: https://bytes.com/topic/perl/insights/903937-how-pass-array-perl-soap-lite-c-web-service

perl # 数组长度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值