开发者

Argument passing to a webservice from iPhone not working

开发者 https://www.devze.com 2023-03-12 14:58 出处:网络
I am trying to connect to a webservic开发者_JS百科e from my xcode project. My setup works with calling methods and gettin return values, but not when i try to pass an argument to the service. Heres my

I am trying to connect to a webservic开发者_JS百科e from my xcode project. My setup works with calling methods and gettin return values, but not when i try to pass an argument to the service. Heres my code:

NSString *soapMsg = @"<?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/\"><soap:Body\n>
<TestArgMethod xmlns=\"http://tempuri.org\">\n
<argument>argument1</argument>
</TestArgMethod>
</soap:Body>
</soap:Envelope>";
NSURL *url = [NSURL URLWithString:@"http://myserver/myservice.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8"  forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/TestArgMethod" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
NSLog(soapMsg);
if (conn) {
       webData = [[NSMutableData data] retain];
} 

and the service written in C# is this:

[Webmethod]
public string TestArgMethod(string argument) {
return argument;
}

Is it something i´m missing with the <argument>argument1</argument> ? The service does not recognize that an argument is sent, only that the method was called. When passing those kind of arguments, do they need to be encoded differently to indicate that its a string?


Your request must be a problem.I am using your string i get many errors.Format your xml value like this and check NSLog.

NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                 "<query>\n"
                                 "<Key>%@</Key>\n"
                                "<Email>%@</Email>\n"
                               "</query>\n",key,email];
NSLog(@"%@",soapMessage);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号