0
我是新的iPhone应用程序开发得到ASMX网页serivce访问, 可以在任何一个告诉我,我如何使用数据,并使用iPhone应用程序访问ASMX web服务中获取数据。 请紧急。 在此先感谢。如何发布和使用iPhone应用程序
我是新的iPhone应用程序开发得到ASMX网页serivce访问, 可以在任何一个告诉我,我如何使用数据,并使用iPhone应用程序访问ASMX web服务中获取数据。 请紧急。 在此先感谢。如何发布和使用iPhone应用程序
我认为ASMX web服务的SOAP Web服务,你应该在这里阅读我的博客文章 -
http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/
首先调用一个SOAP服务,我创建SOAP请求字符串如下。
NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>n"
"<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/">n"
"<soap:Body>n"
"<CelsiusToFahrenheit xmlns="http://tempuri.org/">n"
"<Celsius>50</Celsius>n"
"</CelsiusToFahrenheit>n"
"</soap:Body>n"
"</soap:Envelope>n";
After creating the SOAP request I create a NSMutableRequest to send this request to server.
NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
在发出请求之后,我们可以在NSURLConnection的委托方法中收集XML响应。
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);
[theXML release];
}
统计在theXML字符串XML响应后 - (空)connectionDidFinishLoading:(NSURLConnection的*)连接 我们可以使用解析为TBXML你喜欢的任何其他XML解析器这个字符串。
我加入这个代码,并能够太运行它,但我也越来越阵列作为返回PARAM,我需要捕捉数组列表。 – Selwyn
你可以请在这里回复? – Saurabh
我不知道你是如何获得Web服务响应中的数组?你在XML格式? – Saurabh