iPhone开发 调用wcf服务
2012-03-16 17:42
309 查看
//Web Service Call NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<SOAP-ENV:Envelope \n" "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" "<SOAP-ENV:Body> \n" "<GetData xmlns=\"http://tempuri.org/\">" "</GetData> \n" "</SOAP-ENV:Body> \n" "</SOAP-ENV:Envelope>"]; //[[NSURLCache sharedURLCache] removeAllCachedResponses]; NSURL *url = [NSURL URLWithString:@"http://192.168.1.20:86/Service1.svc"]; 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/IService1/GetData" 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)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 { label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; NSLog(@"Data has been loaded"); NSXMLParser *parser = [[NSXMLParser alloc] initWithData:webData]; [parser setDelegate:self]; [parser parse]; [webData release]; } - (void)parserDidStartDocument:(NSXMLParser *)parser { } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { currentElement = elementName; } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { NSString *fixedString = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; if ([currentElement isEqualToString:@"GetDataResult"]) { label.text=@""; UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"调用wcf成功!" message:fixedString delegate:nil cancelButtonTitle:nil otherButtonTitles:nil] ; [view show]; [view release]; } }
相关文章推荐
- 用WCF开发的服务给Java的客户端调用
- WCF服务开发与调用的完整示例
- WCF :服务开发与调用的完整示例
- 使用WCF进行跨平台开发之二(IIS托管WCF服务并使用php平台调用)
- 跨平台iPhone中调用WCF服务
- iPhone中调用WCF服务“.NET研究”
- 跨平台iPhone中调用WCF服务
- WCF服务开发与调用的完整示例
- WCF实战开发、部署WCF服务计算器、跨机器调用WCF服务
- WCF服务开发与调用的完整示例
- WCF服务开发与调用的完整示例
- 使用WCF进行跨平台开发之三(JAVA调用WCF服务)
- WCF服务开发与调用的完整示例
- iPhone调用WCF服务
- WCF服务开发与调用的完整示例
- WCF服务开发与调用的完整示例
- WCF服务开发与调用的完整示例
- iPhone中调用WCF服务
- 一个WCF服务开发与调用的完整示例
- 一个WCF服务开发与调用的完整示例