在目标C中调用C#webMethod

在目标C中调用C#webMethod,c#,objective-c,http-post,httpresponse,webmethod,C#,Objective C,Http Post,Httpresponse,Webmethod,我试图用这个简单的C#webMethod进行交流: [WebMethod()] public static string login(string userName) { if (userName == "test"){ return "validated"; } return "error"; } 我正试图用以下目标C代码连接到它: NSString *userName = @"test"; NSString *post = [NSString

我试图用这个简单的C#webMethod进行交流:

[WebMethod()]
public static string login(string userName)
{
     if (userName == "test"){
         return "validated";
     }
     return "error";
}
我正试图用以下目标C代码连接到它:

NSString *userName = @"test";
NSString *post = [NSString stringWithFormat:@"userName=%@", userName];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSString *serverURLString = @"http://myURL.aspx/login";
NSURL *serverURL = [NSURL URLWithString:serverURLString];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverURL];
[request setHTTPMethod:@"POST"];
[request addValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

NSHTTPURLResponse *urlResponse = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"result = %@", result);
我得到的不是打印“已验证”或“错误”,而是:

结果=

有人能告诉我web方法或Objective C代码是否有明显的错误吗?谢谢。

我相信WebMethods是SOAP,所以与其手动操作,为什么不使用API来处理SOAP呢?例如。

谢谢,我刚刚进入Obj-C领域,从未听说过这个API,但如果它能使整个过程更简单,那对我来说就行了。我会去看看的。我最终让它工作了,尽管我不完全确定如何工作。我认为服务器最初的设置方式有错误。尽管如此,我还是会研究wsdl2objc,看看它是否有助于流程的其余部分,所以我会接受这个答案。
result = <!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="login" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"   value="/wEPDwULLTE2MTY2ODcyMjlkZFwRG2UySOwu+02xaz+VP6mmD60UBRkXvHCHxGohOt9d" />
<div>    
</div>
</form>
</body>
</html>