如何RestFull WCF Post方法接受任何数据类型输入参数

时间:2015-10-07 12:18:48

标签: wcf http-status-code-404 wcf-rest

我是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个错误请求。当他们在没有参数的情况下使用它时(只调用没有输入参数的方法),它就可以了。我认为可能存在一些参数类型问题。 请帮帮我。

0 个答案:

没有答案