sudzc 101(回应问题)

时间:2012-02-18 01:56:56

标签: objective-c ios4 soap sudzc

我相信这对你的专家来说非常简单。设置了SUDZC,一切似乎都正常工作,但是当一个值返回给委托时,它为空。 NSLog显示正确的XML响应,所以我知道它正常工作,但代码中的值显示为null。 SUDZC附带一个示例程序,这就是它的运行方式。我在网络服务“WhatsYourFavoriteMovie”上创建了一个测试功能,它返回“Pulp Fiction”。日志记录清楚地显示返回的值。为什么是最终值(null)?请帮忙,谢谢。

所以我打电话给...

[service WhatsYourFavoriteMovie:self action:@selector(WhatsYourFavoriteMovieHandler:) userid: 1];

然后当Web服务响应时,它会转到...

// Handle the response from WhatsYourFavoriteMovie.
- (void) WhatsYourFavoriteMovieHandler: (id) value {

// Handle errors
if([value isKindOfClass:[NSError class]]) {
NSLog(@"%@", value);
return;
}

// Handle faults
if([value isKindOfClass:[SoapFault class]]) {
NSLog(@"%@", value);
return;
}


// Do something with the NSString* result
NSString* result = (NSString*)value;
NSLog(@"WhatsYourFavoriteMovie returned the value: %@", result);
}

然而“值”和“结果”始终为“空”...正如您在下面的NSLog输出中所看到的那样,它在标签中返回“Pulp Fiction”。我哪里错了?

2012-02-17 17:27:41.487 SudzCExamples[2782:f803] Loading:     https://www.mydomain.com/tk_services/tk.asmx

2012-02-17 17:27:41.491 SudzCExamples[2782:f803] <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"     
xmlns="com.mynamespace"><soap:Body><WhatsYourFavoriteMovie>
<userid>1</userid></WhatsYourFavoriteMovie></soap:Body></soap:Envelope>

2012-02-17 17:27:41.497 SudzCExamples[2782:f803]
Applications are expected to have a root view controller at the end of application launch

2012-02-17 17:27:45.947 SudzCExamples[2782:f803]
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>
<WhatsYourFavoriteMovieResponse xmlns="com.mynamespace">
<WhatsYourFavoriteMovieResult>Pulp Fiction</WhatsYourFavoriteMovieResult>
</WhatsYourFavoriteMovieResponse></soap:Body></soap:Envelope>

2012-02-17 17:27:45.949 SudzCExamples[2782:f803] WhatsYourFavoriteMovie returned the value: (null)"

再次,正如您在日志中看到的那样,它从服务器获得了“纸浆小说”的值,但是日志的最后一行表示它返回值“null”。请帮我!!谢谢。

3 个答案:

答案 0 :(得分:3)

我对Sudzc生成的代码的ARC版本有完全相同的问题,但无论出于何种原因,非ARC版本工作正常

更新

查看此issue report。我在第一条评论中提出了更改,ARC版本工作正常。

答案 1 :(得分:0)

尝试在didrecivedata中NSLog响应。在SoapRequest.m类中

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)value {

    NSString *str=[[NSString alloc]initWithData:value encoding:NSUTF8StringEncoding];

    NSLog(@"data receives %@",str);

}

然后你会知道确切的问题是什么。 在完成此操作后发布回复,我们会帮助您。

答案 2 :(得分:0)

如果您使用ARC版本,请在SoapRequest中更改行

CXMLNode* element = [[Soap getNode: [doc rootElement] withName:@"Body"] childAtIndex:0];

CXMLNode* element = [[Soap getNode: [doc rootElement] withName:@"soap:Body"] childAtIndex:0];