tags:

views:

298

answers:

2

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/\"&gt;\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/"&gt;
    <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.

A: 

After many web searches I found an answer.

I Used the tool SoapUI (http://www.soapui.org/) to send some soap messages to my webservice. SoapUI displayed the XML message that it sent to the web service, so I found out that my message syntax in the iPhone application was not correct.

Instead of:

 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/\"&gt;\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
  ];

It has to be this:

    NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zdf=\"http://meijberg.topicus.local/zdfmobiel\"&gt;\n"
"<soapenv:Body>\n"
"<zdf:getVerzekerde>\n"
"<zdf:bsn>%@</zdf:bsn>\n"
"</zdf:getVerzekerde>\n"
"</soapenv:Body>\n"
"</soapenv:Envelope>\n", bsnInput.text
];

Still, I don't really understand why this works.. Probably it has something to do with the semi-colon keywords that are in all the tags. Can someone give an explanation of this?

Rick
A: 

I also got one problem that snding & and < symbol does not updated on my .net server ,don`t know whether the url is going to server or not

crystal