Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 2.87 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get iOS to talk to .NET web service
  2. - (void)startRetrievingHotels
  3. {    
  4.     //Create the web service URL
  5.     NSURL *url = [NSURL URLWithString:@"https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"];
  6.  
  7.     //Create the web service request
  8.     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  9.  
  10.     NSString *requestString = [self buildHotelListRequest];
  11.     NSLog(@"%@", requestString );
  12.  
  13.     [request setDelegate:self];
  14.     [request setUsername:@"asdfasdf@asdfasdf.com"];
  15.     [request setPassword:@"asdfasdfasdfasdf$"];
  16.     [request appendPostData:[[self buildHotelListRequest] dataUsingEncoding:NSUTF8StringEncoding]]; //Set the xml request
  17.     [request startAsynchronous];
  18. }
  19.  
  20. - (NSString *)buildHotelListRequest
  21. {
  22.  
  23.  
  24.     NSString *result = [NSString stringWithFormat: @"<?xml version="1.0"?>"
  25.     @"<GetUserName xmlns="https://www.sdf.com/" />"];
  26.  
  27.     NSLog(@"HOTEL LIST REQUEST: %@", result);
  28.  
  29.     return result;
  30. }
  31.        
  32. > <?xml version="1.0" encoding="utf-8"?><soap:Envelope
  33. > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  34. > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  35. > xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><soap12:Upgrade
  36. > xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:SupportedEnvelope
  37. > qname="soap:Envelope"
  38. > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />
  39. >
  40. > <soap12:SupportedEnvelope qname="soap12:Envelope"
  41. > xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" />
  42. >
  43. > </soap12:Upgrade></soap:Header><soap:Body><soap:Fault>
  44. >
  45. > <faultcode>soap:VersionMismatch</faultcode><faultstring>Possible SOAP
  46. > version mismatch: Envelope namespace https://www.stratexsystems.com/
  47. > was unexpected. Expecting
  48. > http://schemas.xmlsoap.org/soap/envelope/.</faultstring>
  49. >
  50. > <detail /></soap:Fault></soap:Body>
  51. >
  52. > </soap:Envelope>
  53.        
  54. NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>
  55. <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/">
  56. <soap:Body>
  57. <GetUserName xmlns="https://www.stratexsystems.com/" />
  58. </soap:Body>
  59. </soap:Envelope>";
  60. NSURL *url = [NSURL URLWithString:@"https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"];
  61. NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
  62. NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
  63. [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  64. [theRequest addValue: @"https://www.stratexsystems.com/GetUserName" forHTTPHeaderField:@"SOAPAction"];
  65. [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
  66. [theRequest setHTTPMethod:@"POST"];
  67. [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  68.  
  69. NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];