从IOS连接到ASP.Net Web服务

从IOS连接到ASP.Net Web服务,asp.net,objective-c,web-services,ios5,Asp.net,Objective C,Web Services,Ios5,我正在编写一个IPad应用程序,它需要连接一个返回整数的Web服务,如下所示: <int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">0</int> NSError *error = nil; NSDictionary *dict = [XMLReader dictionaryForXMLData:self.responseData error:&error]; NSNumber *re

我正在编写一个IPad应用程序,它需要连接一个返回整数的Web服务,如下所示:

<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">0</int>
NSError *error = nil;
NSDictionary *dict = [XMLReader dictionaryForXMLData:self.responseData error:&error];
NSNumber *result = [dict valueForKey:@"int"];
if(error||!result){
    // handle error (either the result is not xml format, or the xml doesn't contain a 'int' key)
}
else {
    // handle result
}

连接确实完成了加载,但我无法从结果中获取值0。正确的方法是什么。谢谢你

我假设你得到了结果,所以我只会对解析做出回应

我通常使用xml进行简单的xml解析。您还可以使用其他第三方库,或者直接使用
NSXMLParsing
,但是,您需要为此编写更多的代码

使用它,解析代码如下所示:

<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">0</int>
NSError *error = nil;
NSDictionary *dict = [XMLReader dictionaryForXMLData:self.responseData error:&error];
NSNumber *result = [dict valueForKey:@"int"];
if(error||!result){
    // handle error (either the result is not xml format, or the xml doesn't contain a 'int' key)
}
else {
    // handle result
}

我还没有测试过这段代码,但它应该基本正确。

请创建基于REST的Web服务,因为它很容易与DB交互并转到JSON

你用哪个解析器来切割XML?@Girish你可以看到我还没有尝试使用XML解析器。在这种情况下,我们需要使用XML解析器吗?