将元素附加到现有的 SOAP::Data 复杂类型 [英] Append an element to an already existing SOAP::Data complex type

查看:48
本文介绍了将元素附加到现有的 SOAP::Data 复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SOAP、PERL 以及几乎所有我被要求做的其他事情都很陌生,所以我希望有人能指出我正确的方向.

I'm very new to SOAP, PERL and pretty much everything else I've been asked to do so I'm hoping someone can point me in the right direction.

我实现了一个简单的 WCF 解决方案,并编写了一个 PERL 客户端,它使用 SOAP::lite 和 SOAP::Data 将复杂数据结构"传递给解决方案.到目前为止,所有这些都非常有效,WCF 解决方案将数组视为一个数组,我能够在服务器端遍历该数组就好了.

I've implemented a simple WCF solution and I've written a PERL client which passes a "complex data structure" to the solution using SOAP::lite and SOAP::Data. All this works very well so far, WCF solution see's the array as an array and I'm able to iterate through the array on the server side just fine.

但是,我在尝试将数据元素附加到 PERL 端的数组时遇到了问题.我有以下代码,它构建了我需要的数组,但稍后我需要在代码中向数组附加几行,但我不知道如何去做.

However, I'm having an issue trying to append a data element to the array on the PERL side. I have the following code, which builds the array I need, but I need to append a few lines to the array later on in the code and I can't figure out how to that.

# build array of values
my $data= SOAP::Data->new
(name => 'array', value => 
   [
     SOAP::Data->new(name => 'elem:string', value => 'firststring'),
     SOAP::Data->new(name => 'elem:string', value => 'secondstring'),
     SOAP::Data->new(name => 'elem:string', value => 'thridstring')
   ]
) 
->attr
( 
   { 'xmlns:elem' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays','xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance'}
);

# create a new element
my $elem1 = SOAP::Data->new(name => 'elem:string', value => 'addedstring');

# try to add the element
push(@{$data->{array}},$elem1);

#.... send, catch, print.. bla bla bla

我运行的代码和 WCF 服务看到的数组很好,但 $elem1 值实际上从未附加到 SOAP 信封.

The code I have runs, and the WCF service see's the array just fine, but the $elem1 value is never actually appended to the SOAP envelope.

非常感谢任何帮助...

Any help is GREATLY appreciated...

推荐答案

看看 $data 使用的是什么 Data::Dumper,你就明白了

Take a look at what $data is using Data::Dumper, you get this

$VAR1 = bless( {
             '_attr' => {
                          'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance',
                          'xmlns:elem' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
                        },
             '_signature' => [],
             '_name' => 'array',
             '_value' => [
                           [
                             bless( {
                                      '_value' => [
                                                    'firststring'
                                                  ],
                                      '_name' => 'string',
                                      '_prefix' => 'elem',
                                      '_signature' => [],
                                      '_attr' => {}
                                    }, 'SOAP::Data' ),
                             bless( {
                                      '_value' => [
                                                    'secondstring'
                                                  ],
                                      '_name' => 'string',
                                      '_signature' => [],
                                      '_prefix' => 'elem',
                                      '_attr' => {}
                                    }, 'SOAP::Data' ),
                             bless( {
                                      '_attr' => {},
                                      '_value' => [
                                                    'thridstring'
                                                  ],
                                      '_name' => 'string',
                                      '_signature' => [],
                                      '_prefix' => 'elem'
                                    }, 'SOAP::Data' )
                           ]
                         ]
           }, 'SOAP::Data' );

没有$data->{array}

查看 SOAP::Data 的文档,说您应该使用 $data->value 来访问您创建的数组.

A look at the documentation for SOAP::Data, says you should use $data->value to access the array you created.

push @{ $data->value }, $elem1;

print Dumper $data->value;

收益

$VAR1 = [
      bless( {
               '_attr' => {},
               '_prefix' => 'elem',
               '_value' => [
                             'firststring'
                           ],
               '_name' => 'string',
               '_signature' => []
             }, 'SOAP::Data' ),
      bless( {
               '_signature' => [],
               '_name' => 'string',
               '_value' => [
                             'secondstring'
                           ],
               '_prefix' => 'elem',
               '_attr' => {}
             }, 'SOAP::Data' ),
      bless( {
               '_name' => 'string',
               '_signature' => [],
               '_value' => [
                             'thridstring'
                           ],
               '_prefix' => 'elem',
               '_attr' => {}
             }, 'SOAP::Data' ),
      bless( {
               '_attr' => {},
               '_prefix' => 'elem',
               '_value' => [
                             'addedstring'
                           ],
               '_name' => 'string',
               '_signature' => []
             }, 'SOAP::Data' )
    ];

这篇关于将元素附加到现有的 SOAP::Data 复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆