如何使用iPhone应用程序发布和获取asmx web服务访问权限?

如何使用iPhone应用程序发布和获取asmx web服务访问权限?,iphone,web-services,Iphone,Web Services,我是iPhone应用程序开发新手。我如何通过使用iPhone应用程序访问asmx web服务来发布数据和获取数据?我认为asmx web服务是SOAP web服务。你应该在这里阅读我的博客- 要首先调用SOAP服务,我使用SOAP请求创建一个字符串,如下所示 NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>n" "<soap:Envelope xmlns:xsi="http://

我是iPhone应用程序开发新手。我如何通过使用iPhone应用程序访问asmx web服务来发布数据和获取数据?

我认为asmx web服务是SOAP web服务。你应该在这里阅读我的博客-

要首先调用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");
}
在-(void)connectionIDFinishLoading:(NSURLConnection*)连接中收集XML字符串中的XML响应后
我们可以使用您喜欢的任何其他XML解析器来解析此字符串。

我已经添加了此代码,并且能够运行它,但是我还获取了数组作为返回参数,并且需要捕获数组列表。您可以在此处发布响应吗?我不确定您是如何在webservice响应中获取数组的?你得到的是xml格式的吗?不,我的意思是我想处理和数组列表,它是从web服务返回的,我需要在iPhone代码中处理它。我不知道你是如何得到数组响应的(对不起,我没有任何.net exp)。但是,如果您谈论的是从xml响应获取这些数据,那么您可以看看这个非常好的TBXML库-
-(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];
}