0
iOS的代碼,這是消耗我的WCF是創造寧靜的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 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 bad request
回覆。當它們在沒有參數的情況下使用它(只是調用沒有輸入參數的方法)時,它是可以的。我認爲可能有一些參數類型的問題。
問題是什麼?
這WCF工作從我的測試應用程序的罰款(我做了一個測試應用程序,並試圖消耗這個WCF)。 甚至,當Ios應用程序使用相同的,沒有參數時它工作正常。 – Ananda90