Click here to Skip to main content
14,971,029 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; }

}
Posted
Updated 7-Oct-15 18:55pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900