title: iPhone APP accessing .net WCF service and get the results in label
body: <p>Am a .Net programmer and a newbie into iPhone APPs and Obj C.</p>
  
  <p>My requirement is as follows.</p>
  
  <p>I need an iPhone App which consumes a method in .net WCF service and will show the results in a label or textbox in the iPhone.</p>
  
  <p>I have the wcf for multiplying 2 numbers.When I did NSLog, it was getting me the results there.But I need only the value i.e I give 5*10 and I need 50 in my label.Instead its giving the entire stuff..</p>
  
  <p>Please find my code here.</p>
  
  <p>the h file</p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
  
  @interface iServiceViewController : UIViewController {
         UILabel *label;
         NSMutableData *webData;
  }
  @property(nonatomic,retain) IBOutlet UILabel *label;
  @end
  </code></pre>
  
  <p>the m file</p>
  
  <pre><code>#import "iServiceViewController.h"
  
  @implementation iServiceViewController
  @synthesize label;
  
  
  
  // Implement viewDidLoad to do additional setup after loading the
  view, typically from a nib.
  - (void)viewDidLoad {
     [super viewDidLoad];
         NSString *soapMessage = [NSString stringWithFormat:
                                                          @"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n"
                                                          "&lt;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/\"&gt; \n"
                                                          "&lt;SOAP-ENV:Body&gt; \n"
                                                          "&lt;GetProduct xmlns=\"http://tempuri.org/\"&gt;"
                                                          "&lt;first&gt;100&lt;/first&gt;&lt;second&gt;10&lt;/second&gt;"
                                                          "&lt;/GetProduct&gt;\n"
                                                          "&lt;/SOAP-ENV:Body&gt; \n"
                                                          "&lt;/SOAP-ENV:Envelope&gt;"];
         NSURL *url = [NSURL
  URLWithString:@"http://192.168.0.115:1010/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/GetProduct"
  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");
  
         //NSString *responseString = [[NSString alloc] initWithData:webData
  encoding:NSUTF8StringEncoding];
         //NSInteger *responseInt = [[NSInteger alloc] initWithData:webData
  encoding:NSInteger];
         NSString *responseString = [[NSString alloc] initWithData:webData
  encoding:NSUTF8StringEncoding];
         [webData release];
  
         //label.text =  responseString;
         NSLog(responseString);
  
         [responseString release];
  
  }
  
  - (void)dealloc {
     [super dealloc];
  }
  
  @end
  </code></pre>
  
  <p>My output NSLOG</p>
  
  <pre><code>[Session started at 2011-04-21 12:04:48 +0300.]
  2011-04-21 12:04:49.579 iService[1978:207] Data has been loaded
  2011-04-21 12:04:49.580 iService[1978:207] &lt;s:Envelope
  xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;s:Body&gt;&lt;GetProductResponse
  xmlns="http://tempuri.org/"&gt;&lt;GetProductResult&gt;1000&lt;/GetProductResult&gt;&lt;/GetProductResponse&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;
  </code></pre>
  
  <p>--</p>
  
  <p>I tried to multiply 100 by 10 and I got the result also. but how can I print just 1000 in my label or any outlet..</p>
  
  <p>Thanks in advance..</p>
  
  <p>Renju</p>