Note that there are some explanatory texts on larger screens.

plurals
  1. POParameters are not working when calling WebService
    text
    copied!<p>I have created a .NET-WebService with the fallowing WebMethod:</p> <pre><code> [WebMethod] public DataSet getMyDataset(string param1, string param2) { var ret = new DataSet(); var dt = new DataTable(); dt.Columns.Add("pk", typeof (string)); dt.Rows.Add("aaa"); dt.Rows.Add("bbb"); dt.Rows.Add("ccc"); ret.Tables.Add(dt); return ret; } </code></pre> <p>I am calling it in objective-c like the fallowing way:</p> <pre><code> NSMutableString *sRequest = [[NSMutableString alloc] init]; self.SOAPActionURL = [NSString stringWithFormat:@"%@%@",self.XMLNameSpace, self.MethodName]; //make soap request [sRequest appendString:@"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"]; [sRequest appendString:@"&lt;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;"]; [sRequest appendString:@"&lt;soap:Body&gt;"]; [sRequest appendString:[NSString stringWithFormat:@"&lt;%@ xmlns=\"%@\"&gt;",MethodName, XMLNameSpace]]; if(MethodParametersAsString != nil) [sRequest appendString:MethodParametersAsString]; NSEnumerator *tableIterator = [MethodParameters keyEnumerator]; NSString *keyID; while(keyID = [tableIterator nextObject]) { [sRequest appendString:[NSString stringWithFormat:@"&lt;%@&gt;%@&lt;/%@&gt;", keyID, [MethodParameters objectForKey:keyID], keyID]]; NSLog(@"Method: %@ Parameter:%@ Value:%@",self.MethodName, keyID, [MethodParameters objectForKey:keyID], [NSString stringWithFormat:@"&lt;%@&gt;%@&lt;/%@&gt;", keyID, [MethodParameters objectForKey:keyID], keyID]); } //close envelope [sRequest appendString:[NSString stringWithFormat:@"&lt;/%@&gt;", MethodName]]; [sRequest appendString:@"&lt;/soap:Body&gt;"]; [sRequest appendString:@"&lt;/soap:Envelope&gt;"]; NSLog(sRequest); NSURL *myWebserverURL = [NSURL URLWithString:XMLURLAddress]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL]; [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request addValue:self.SOAPActionURL forHTTPHeaderField:@"SOAPAction"]; [request setHTTPMethod:@"POST"]; NSData *envelope = [sRequest dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:envelope]; [request setValue:[NSString stringWithFormat:@"%d", [envelope length]] forHTTPHeaderField:@"Content-Length"]; //[sRequest NSError *WSerror = nil; NSURLResponse *WSresponse = nil; NSMutableData *myMutableData = (NSMutableData *)[NSURLConnection sendSynchronousRequest:request returningResponse:&amp;WSresponse error:&amp;WSerror]; </code></pre> <p>which will create and send the following soap-message:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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; &lt;soap:Body&gt; &lt;getMyDataset xmlns="http://symas-design.ch"&gt; &lt;param1&gt;val1&lt;/param1&gt; &lt;param2&gt;val2&lt;/param2&gt; &lt;/getMyDataset&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>Now my problem:</p> <p>The WebMethod getMyDataset is called correctly - but the parameters param1 and param2 are always null (instead of val1 and val2 in this sample). The Return-value of getMyDataset is also correct transfered back to the iPhone. Only the Parameters are not coming to getMyDataset. What I am doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload