I'm trying to consume an ASMX web service from objective-c using the wsdl2objc tool. For now, I'm trying to consume the temperature conversion web service.
Using the tool, client classes got generated for consuming the service (I have used THIS link as reference to write the code).
However, I'm continuously getting this soap fault message "Unable to handle request without a valid action parameter. Please supply a valid soap action".
While this error message very clearly states that I need to add a "SOAPAction" header to my request headers, I don't know how to do that in this case when using this wsdl2objc tool to generate the client classes for consuming the web service.
I have searched for a long time but in all the links that I referred, there was no mention of this situation occurring in objective-c.
Please check my code below:
- (IBAction)submitClicked:(id)sender {
TempConvertSoap *binding = [TempConvertSvc TempConvertSoap];
TempConvertSoapResponse* response;
TempConvertSvc_CelsiusToFahrenheit* request = [[TempConvertSvc_CelsiusToFahrenheit alloc] init];
request.Celsius = self.txtCelcius.text;
response = [binding CelsiusToFahrenheitUsingParameters:request];
dispatch_async(dispatch_get_main_queue(), ^{
[self processResponse:response];
});
}
-(void) processResponse: (TempConvertSoapResponse *) soapResponse
{
NSArray *responseBodyParts = soapResponse.bodyParts;
id bodyPart;
@try{
bodyPart = [responseBodyParts objectAtIndex:0];
}
@catch (NSException* exception)
{
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Server Error"message:@"Error while trying to process request" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
return;
}
if ([bodyPart isKindOfClass:[SOAPFault class]]) {
NSString* errorMesg = ((SOAPFault *)bodyPart).simpleFaultString;
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Server Error" message:errorMesg delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
else if([bodyPart isKindOfClass:[TempConvertSvc_CelsiusToFahrenheitResponse class]]) {
TempConvertSvc_CelsiusToFahrenheitResponse* tempResponse = bodyPart;
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Success!" message:[NSString stringWithFormat:@"Result is %@", tempResponse.CelsiusToFahrenheitResult] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}
By referring to THIS link, I have also tried to directly consume the web service by manually creating the soap message and making a call but I'm getting the HTML of the asmx web page as a response!! I just can't understand why I would get such a response!! I have not changed even a single line of code while running this particular code example given in the link referred at the start of this paragraph.
I'm totally new to iOS programming and might be doing some silly mistake or missing something very trivial. Can someone kindly help?
Please do let me know if any more information is required.
Thank you.
Update:
As suggested by Priya below, I checked the soap action header item in the setHttpCallUsingBody method. However, I see that it is already being set. But still I'm getting the same fault message. Check the screen clip below. Is the soap action not correct? Should it be something different?