0

I used NSURLConnection to communicate with Soap webservice and it worked fine.

Now I am using ASIFormDataRequest and I am not getting is it necessary to create soap message for that? and I am not aware what is SoapAction.

Here is the code I am using

NSURL *url = [NSURL URLWithString:@"http://SERVERNAME.com/WEBSERVICENAME"];

[self setFrmdataReq:[ASIFormDataRequest requestWithURL:url]];
[frmdataReq setRequestMethod:@"POST"];
[frmdataReq addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];

[frmdataReq setPostValue:txtField.text forKey:@"city"];
[frmdataReq setDelegate:self];
[frmdataReq setDidFinishSelector:@selector(requestFinished:)];
[frmdataReq setDidFailSelector:@selector(requestFailed:)];
[frmdataReq startSynchronous];

UPDATE

Soap Message I used,

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\
                             <soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\
                             <soap12:Body>\
                             <getCityTime xmlns=\"http://www.Nanonull.com/TimeService/\">\
                             <city>%@</city>\
                             </getCityTime>\
                             </soap12:Body>\
                             </soap12:Envelope>",txtField.text];


    NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];

    [request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];

    [request addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    if(conn)
    {
        responseData = [[NSMutableData data]retain];
        NSLog(@"connection successful");
    }
    else
        NSLog(@"connection fail.");

I didn't defined SOAPAction as I don't know anything about that.

Heena
  • 2,348
  • 3
  • 32
  • 58
  • ASIHTTPRequest will not create the SOAP data for you, you still need to do that yourself, the same as with NSURLConnection. If you post the working NSURLConnection code, we can tell you how to write the same code using ASIHTTPRequest. – JosephH Dec 23 '11 at 11:37
  • If we need to create soap message then what will be difference in using NSURLConnection and ASIHttpRequest? and in that case how can we use setPostValue method of ASIFormDataRequest? – Heena Dec 26 '11 at 06:22

1 Answers1

0

When using ASIHTTPRequest, you need to create the SOAP request in basically the same way as you do with NSURLConnection.

The setPostValue call in ASIHTTPRequest is for create HTTP POST requests in the same format use for POST <form> tags in HTML.

For comparing ASIHTTPRequest / NSURLConnection, see things like:

ASIHTTPRequest vs NSURLConnection

and "What is ASIHTTPRequest?" on:

http://allseeing-i.com/ASIHTTPRequest/

Community
  • 1
  • 1
JosephH
  • 37,173
  • 19
  • 130
  • 154
  • I have go through the same link http://allseeing-i.com/ASIHTTPRequest/ but there isn't any specification for creating SOAP message – Heena Jan 02 '12 at 04:15
  • ASIHTTPRequest has no explicit support for SOAP - you just do it the same way you were with NSURLConnection. ie. create a POST request, set your SOAP xml as the body and set the Content-Type to text/xml. – JosephH Jan 02 '12 at 10:22