Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 493659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:25:36+00:00 2026-05-13T05:25:36+00:00

I need to wait for a response from a SOAP webservice, I am calling

  • 0

I need to wait for a response from a SOAP webservice, I am calling via a NSURLConnection as I need to manipulate the data being returned and then return it from my class to the calling class..

Here is my code:

#import <Foundation/Foundation.h>


@interface UsersBLL : NSObject {

 NSMutableData *webData;
 NSMutableString *soapResults;
 NSXMLParser *xmlParser;
 BOOL *recordResults;
 NSNumber *EmailCount;
}

@property(nonatomic, retain) NSMutableData *webData;
@property(nonatomic, retain) NSMutableString *soapResults;
@property(nonatomic, retain) NSXMLParser *xmlParser;



-(int)checkEmailAddress:(NSString*)emailAddress;
@end

#import "UsersBLL.h"


@implementation UsersBLL
@synthesize webData;
@synthesize soapResults;
@synthesize xmlParser;

-(id)init {
 self = [super init];
 return self;
}

-(int)checkEmailAddress:(NSString*)emailAddress {
 // Build the SOAP envelope
 NSString *soapMessage = [NSString stringWithFormat:
        @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
        "<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/\">\n"
        "<soap:Body>\n"
        "<CheckEmailAddress xmlns=\"http://tempuri.org/\">\n"
        "<EmailAddress>%@</EmailAddress>\n"
        "</CheckEmailAddress>\n"
        "</soap:Body>\n"
        "</soap:Envelope>\n", emailAddress];

 NSLog(soapMessage);

 NSURL *url = [NSURL URLWithString:@"http://photoswapper.mick-walker.co.uk/UsersService.asmx?op=CheckEmailAddress"];
 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/CheckEmailAddress" 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");
 }
 NSLog(@"%@", EmailCount);
}

-(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(@"ERROR with theConenction");
 [connection release];
 [webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
 NSLog(@"DONE. Received Bytes: %d", [webData length]);
 NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
 NSLog(theXML);
 [theXML release];

 if( xmlParser )
 {
  [xmlParser release];
 }

 xmlParser = [[NSXMLParser alloc] initWithData: webData];
 [xmlParser setDelegate: self];
 [xmlParser setShouldResolveExternalEntities: YES];
 [xmlParser parse];

 [connection release];
 [webData release];
}

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
   attributes: (NSDictionary *)attributeDict
{
 if( [elementName isEqualToString:@"CheckEmailAddressResult"])
 {
  if(!soapResults)
  {
   soapResults = [[NSMutableString alloc] init];
  }
  recordResults = TRUE;
 }
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
 if( recordResults )
 {
  [soapResults appendString: string];
 }
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
 if( [elementName isEqualToString:@"CheckEmailAddressResult"])
 {
  recordResults = FALSE;
  NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];
  EmailCount = [formatter numberFromString:soapResults];
            [formatter release];
  [soapResults release];
  soapResults = nil;
 }
}

@end

CheckEmailAddress is declared as returning an integer value (I know it returns nothing in the sample above).

What I ideally want, is through the CheckEmailAddress method, return the value retrieved from the web service. However as the call NSURLConnection does not wait until the request has completed, I cannot do it.

I would be grateful if anyone could give me any potential ideas for workarounds.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:25:36+00:00Added an answer on May 13, 2026 at 5:25 am

    The simplest solution would be using [NSURLConnection sendSynchronousRequest:returningResponse:error:].

    It does not allow as much control as the approach you’ve taken, but is usually enough for most applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make multiple asynchronous calls from inside a wcf service hosted in
I have an ASP.NET website and from one of the web pages I need
I really hate when I want to store/fetch something from the database, I have
After talking with a friend of mine from Google, I'd like to implement some
This is not an AJAX request/response callback question... I am building a grid using
I have a project, which has a server listening on port 9999. Originally the
I have a problem returning an object that was created in other thread. The
That title is a mouthful and a bit confusing, but you are still reading
Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
I have an application that runs with Twilio. The idea is that you will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.