Hello,
I am developing an iPhone application which sends SOAP messages to a .NET Webservice to call several WebMethods. These methods getting data out of a database and return this in a SOAP message back to the iPhone.
When i sent a SOAP message that calls the WebMethod without any parameters it works just fine.
But when I pass a parameter with the message, the webMethod parameter stays null in the visual studio debugger. It looks like the WebMethod doesn't receive anything.
I Used a network sniffer to look at the incoming packets and noticed that the SOAP message is okay when it comes in. So it must be something at the webservice side that's going wrong.
Here some code:
The WebMethod:
public class ZDFMobielWebservice : System.Web.Services.WebService
{
[WebMethod]
public string getVerzekerde(string bsn)
{
string result = bsn;
ZDFKoppeling koppeling = new ZDFKoppeling();
result = koppeling.getData(Convert.ToInt32(bsn));
return result;
}
}
The function that creates the SOAP Message:
-(IBAction)buttonClick:(id)sender
{
recordResults = FALSE;
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"
"<getVerzekerde xmlns=\"http:/meijberg.topicus.local/zdfmobiel\">\n"
"<bsn>%@</bsn>\n"
"</getVerzekerde>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", bsnInput.text
];
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"http://meijberg.topicus.local/ZDFMobielWebservice.asmx"];
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://meijberg.topicus.local/zdfmobiel/getVerzekerde" 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");
}
//[nameInput resignFirstResponder];
}
And here the SOAP message:
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<getVerzekerde xmlns="http:/meijberg.topicus.local/zdfmobiel">
<bsn>999999999</bsn>
</getVerzekerde>
</soap:Body>
</soap:Envelope>
Anyone who knows what the problem might be?
EDIT: When I invoke the webmethod from the webpage that is automatically generated by the webserver it works good. Then the parameter is filled with the value I entered.