Calling WCF Service in iOS Select DataBase
Calling WCF Service in iOS Select DataBase
- connect button (IBAction)buttonClick and coding in ViewController.m
 
 
 
 
 
- connect button (IBAction)buttonClick and coding in ViewController.m
-(IBAction)buttonClick:(id)sender
{
 webData = [[NSMutableData alloc] init];
 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/\">""<name>NOOKOWL</name>"
 "</GetData> \n"
 "</SOAP-ENV:Body> \n"
 "</SOAP-ENV:Envelope>"];
 NSURL *url = [NSURL URLWithString:@"http://[Address or localhost]/Activate/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
{
    NSLog(@"Conenction failed: %@:", [error description]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [connection release];
    NSString * response = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
    [webData release];
    NSLog(@"%@ ::",response);
    [response release];
}
-webData > NSMutableData  init in ViewController.h
@property(nonatomic, retain) NSMutableData *webData;  [ .h ]
@synthesize webData  [ . m ]
Run and Click Button result is response NSString Variable Show in NSLog 
Comments
Post a Comment