When iOS is consuming this WCF, it replies with 400 bad request. When they are consuming it without parameter (just calling the method without input parameters), it's OK. I think there may be some parameter type issue.
What could the issue be?
The iOS code, which is consuming my WCF is:
#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
---------------------------------------------------------------------
The WCF code is:
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; }
}