Objective C - sudzc,返回空 ArrayOfString,但 xml 响应包含数据

发布于 2025-01-03 06:19:47 字数 3170 浏览 6 评论 0原文

我是 Objective C 的新手。我正在尝试使用 sudcz 来使用 Web 服务。 我已经用 PHP 和 MySQL 创建了 Web 服务服务器,现在我想与服务器通信并获得相关结果。

调用方法时,我从服务器获取正确的 XML 响应,但返回的 ArrayOfString 类型的对象似乎为空。 NSLog 仅打印,我假设 sudzc 无法将 xml 解析为适当的形式,因此返回的对象为空,我错了吗?或者我只是看不到或无法处理返回的对象?有人有任何线索吗?

如果需要任何材料我会发布它们。 谢谢。

补充:

    CXMLElementNode* element = [[Soap getNode: [doc rootElement] withName: @"Body"] childAtIndex:0];
    if(deserializeTo == nil) {

        output = [Soap deserialize:element];

    } else {
                    NSLog(@"Deserialize to : %@", deserializeTo);
        if([deserializeTo respondsToSelector: @selector(initWithNode:)]) 
                            //problematic section
                            element = [element childAtIndex:0];
                            NSLog(@"NSSstring element : %@", element);
            output = [deserializeTo initWithNode: element];

                  } else {

            NSString* value = [[[element childAtIndex:0] childAtIndex:0] stringValue];
                            NSLog(@"NSSstring value : %@", value);
            output = [Soap convert: value toType: deserializeTo];
        }
           NSLog(@"output : %@", output);
    }

我认为有问题的部分是我放置评论有问题的部分的地方。因为对象元素是 xml 元素,并且在调用 output = [deserializeTo initWithNode: element] 之后,没有任何反应,所以 NSLog(output) 打印与在对象 deserializeTo 上调用消息 initWithNode: element 之前打印的 NSLog(deserializeTo) 相同的输出 我怀疑 SoapObject 实例方法 initWithNode 它无法正常工作,因为 我的 deserializeTo 是类 RSiArrayOfstring 的实例,该类是 SoapObject 的子集,它将此消息委托给父类 (SoapObject),并且 SoapObject 中此消息的实现是:

// Called when initializing the object from a node
- (id) initWithNode: (CXMLNode*) node {
    if(self = [self init]) {
    }
    return self;
}

在执行期间,我看不到

来自调试器的参数节点 OUTPUT 的任何操作这段代码:

2012-02-08 20:22:03.166 URS[1170:b603] Deserialize to : <ArrayOfstring></ArrayOfstring>
2012-02-08 20:23:17.258 URS[1170:b603] NSSstring element : &lt;CXMLElement 0x5d7b920 [0x59701b0] return &lt;return arrayType="SOAP-ENC:Array[6]" type="SOAP-ENC:Array">&lt; item arrayType="xsd:string[1]" type="SOAP-ENC:Array">&lt; item type="xsd:string">1 - Elektroúdržba&lt;/item>&lt; /item>&lt; item arrayType="xsd:string[1]" type="SOAP-ENC:Array">&lt; item type="xsd:string">2 - Zámočnícka dielňa&lt; /item>&lt; /item>&lt; item arrayType="xsd:string[1]" type="SOAP-ENC:Array">&lt; item type="xsd:string">3 - Údržba žeriavov</item>&lt; /item>&lt; item arrayType="xsd:string[1]" type="SOAP-ENC:Array">&lt; item type="xsd:string">6 - Zámočnícká dielňa H4&lt; /item>&lt; /item>&lt; item arrayType="xsd:string[1]" type="SOAP-ENC:Array">&lt; item type="xsd:string">4 - Mechanici&lt; /item>&lt; /item>&lt; item arrayType="xsd:string[1]" type="SOAP-ENC:Array">&lt; item type="xsd:string">5 - Údržba CNC&lt; /item>&lt; /item>&lt; /return>>
2012-02-08 20:56:11.353 URS[1170:b603] output : &lt; ArrayOfstring>&lt; /ArrayOfstring 

I'm newbie in Objective C. I'm trying to consume an webservice with sudcz.
I've got and Webservice server created in PHP an MySQL and now I'd like to comunicate with the server and getting a relevant results.

When calling a method i'm getting corrent XML response from the server but returned object of type ArrayOfString seems to be empty. NSLog prints just <ArrayOfString></ArrayOfString>, i'm assuming sudzc wasn't albe to parse xml in to a aproporiate form therefore the returned object is empty, am I wrong ? or I just cant see or cope with the returned object ? Has someone got any clue ?

If any materials needed i'll post them.
Thx.

Added :

    CXMLElementNode* element = [[Soap getNode: [doc rootElement] withName: @"Body"] childAtIndex:0];
    if(deserializeTo == nil) {

        output = [Soap deserialize:element];

    } else {
                    NSLog(@"Deserialize to : %@", deserializeTo);
        if([deserializeTo respondsToSelector: @selector(initWithNode:)]) 
                            //problematic section
                            element = [element childAtIndex:0];
                            NSLog(@"NSSstring element : %@", element);
            output = [deserializeTo initWithNode: element];

                  } else {

            NSString* value = [[[element childAtIndex:0] childAtIndex:0] stringValue];
                            NSLog(@"NSSstring value : %@", value);
            output = [Soap convert: value toType: deserializeTo];
        }
           NSLog(@"output : %@", output);
    }

I think the problematic section is where I putted comments problematic section. Because object element is xml element and after calling output = [deserializeTo initWithNode: element], nothing happens, NSLog(output) prints the same output as printed NSLog(deserializeTo) before calling message initWithNode: element on object deserializeTo
I suspect SoapObject instance method initWithNode that it doesn't work as it should, because
my deserializeTo is instance of class RSiArrayOfstring a that class is subset of SoapObject and it delegates this message to parent class (SoapObject) and the implementation of this message in SoapObject is :

// Called when initializing the object from a node
- (id) initWithNode: (CXMLNode*) node {
    if(self = [self init]) {
    }
    return self;
}

i can't see any manipulation with argument node

OUTPUT from debugger during executing this code :

2012-02-08 20:22:03.166 URS[1170:b603] Deserialize to : <ArrayOfstring></ArrayOfstring>
2012-02-08 20:23:17.258 URS[1170:b603] NSSstring element : <CXMLElement 0x5d7b920 [0x59701b0] return <return arrayType="SOAP-ENC:Array[6]" type="SOAP-ENC:Array">< item arrayType="xsd:string[1]" type="SOAP-ENC:Array">< item type="xsd:string">1 - Elektroúdržba</item>< /item>< item arrayType="xsd:string[1]" type="SOAP-ENC:Array">< item type="xsd:string">2 - Zámočnícka dielňa< /item>< /item>< item arrayType="xsd:string[1]" type="SOAP-ENC:Array">< item type="xsd:string">3 - Údržba žeriavov</item>< /item>< item arrayType="xsd:string[1]" type="SOAP-ENC:Array">< item type="xsd:string">6 - Zámočnícká dielňa H4< /item>< /item>< item arrayType="xsd:string[1]" type="SOAP-ENC:Array">< item type="xsd:string">4 - Mechanici< /item>< /item>< item arrayType="xsd:string[1]" type="SOAP-ENC:Array">< item type="xsd:string">5 - Údržba CNC< /item>< /item>< /return>>
2012-02-08 20:56:11.353 URS[1170:b603] output : < ArrayOfstring>< /ArrayOfstring 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傻比既视感 2025-01-10 06:19:47

嗨,我刚刚遇到了同样的问题。

我发现

[[Soap getNode: [doc rootElement] withName: @"Body"]

省略了标签的名称空间。因此,在我的例子中,XML 部分如下所示:

<SOAP-ENV:Body>....

将上面的行更改为:

[[Soap getNode: [doc rootElement] withName: @"SOAP-ENV:Body"]

对我的例子有帮助。尽管我不确定命名空间是否因不同的肥皂实现而异。

干杯!

Hi i just ran into the same issue.

I found that

[[Soap getNode: [doc rootElement] withName: @"Body"]

omits the namespace of tags. So in my case the XML part looks like this:

<SOAP-ENV:Body>....

Changing the above line to:

[[Soap getNode: [doc rootElement] withName: @"SOAP-ENV:Body"]

helped in my case. Allthough i am not sure if the namespace varies for different soap implementations.

cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文