Objective c 为iOS创建Restful WCF
使用我的WCF的iOS代码是:Objective c 为iOS创建Restful WCF,objective-c,wcf,rest,Objective C,Wcf,Rest,使用我的WCF的iOS代码是: #import "ViewController.h" //#import "AFNetworking.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically
#import "ViewController.h"
//#import "AFNetworking.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)submitBtnPressed:(id)sender {
NSString *sturl = [NSString stringWithFormat:@"http://servername/authentication/login"];
NSURL *url = [[NSURL alloc] initWithString:sturl];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"userName": @"chanml",
@"password": @"password"
};
[manager POST:sturl parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"JSON: %@", responseObject);
}failure:^(AFHTTPRequestOperation operation, NSError error) {
NSLog(@"Error: %@", error);
}];
}
@end
WCF代码为:
public interface Iauthentication
{
[OperationContract]
void DoWork();
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "login")]
////UriTemplate = "login?userName={userName}&password={password}")]
ResponseData GetLoginData();
//string GetLoginData(string userName, string password);
}
[DataContract(Namespace = "http://tempuri.org")]
public class RequestData
{
[DataMember]
public string userName { get; set; }
[DataMember]
public string password { get; set; }
}
[DataContract]
public class ResponseData
{
[DataMember]
public string username { get; set; }
[DataMember]
public string password { get; set; }
[DataMember]
public string name { get; set; }
}
当iOS使用此WCF时,它会以400错误请求
进行响应。当他们在没有参数的情况下使用它(只调用没有输入参数的方法)时,就可以了。我认为可能存在一些参数类型问题
可能是什么问题?似乎您的合同和服务实现不匹配。但仍然不确定 我对ios代码不太熟悉,无法在这方面为您提供更多指导 您可能已经尝试了几个选项,但对于其他读者,让我尝试介绍一些调试步骤
- 试试小提琴手。小提琴手也会犯同样的错误吗?(一些好链接:)
- 启用WCF跟踪。(链接:)
- 检查您的wcf服务是否正常工作
- 检查innerException消息 -