Tuesday 10 March 2015

Jogendra Singh

SOAP webservice calling in iOS with xml parsing

       
Here we are learning , How to call SOAP webservice in iOS with XML parsing " -

In this tutorial , we will use a third party class for XML parsing that is "XMLReader" 
         NSString *soapMessage = [NSString stringWithFormat:
                             @"\n"
                             "\n"
                             "\n"
                             "<newslist xmlns=\"http://tempuri.org/\">\n"
                             "%@\n"  "</newslist>\n"  "
\n"   "\n",[userDefaults valueForKey:@"languageId" ];  // This XML is not showing proper here show visit on  XML String Type   
Here XML is not showing properly show visit on this url XML String Type

      //newslist = It my webservice name that I am going to call and this XML is showing in your browser if you will call your webservice URL
//pi  = Its variable , In this I am sending data on server of my language id

 NSString *soapAction = [NSString stringWithFormat:@"http://tempuri.org/%@",@"newslist"]; // Here your webservice name that you wants to call 
        NSURL *url = [NSURL URLWithString: @"Enter Here your webservice url" ];
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
            [request setHTTPMethod:@"POST"];
            NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
            [request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
            [request addValue: soapAction forHTTPHeaderField:@"SOAPAction"];
            [request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
            [request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

            NSURLResponse* response;
            NSError* error;
            NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
            NSString *  rsltStr = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
          
            NSError *parseError = nil;
            NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:rsltStr error:&parseError];  // In this I have used XMLReader file

        //you can download XMLReader file her using this like XMLReader FILE DOWNLOAD 

Here in xmlDictionary you will get result from server with xml parsed.


Thanks for Visit  , Also can visit on My blog Facebook page iPhone & iPad Application Development Help World and also can visit Google+ 


Jogendra Singh

About Jogendra Singh -

I'm Founder of Jogendra.Com. I love to share my bright ideas with the whole blogging community. I'm a good iPhone Application Developer. Apart from Blogging, I love to play Cricket and mobile games (Clash of clans).

Subscribe to this Blog via Email :