我有具有以下定义的 ac# web 服务:
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "BCryptLogin")]
LoginResponse BCryptLogin(LoginData logindata);
实际功能是
public LoginResponse BCryptLogin(LoginData logindata)
{
string login = logindata.login;
string password = logindata.password;
// code be here
}
当尝试访问“logindata.login”时,我得到一个 NullReferenceException:
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=LoginService
StackTrace:
at LoginService.LoginService.BCryptLogin(LoginData logindata) in C:\services\LoginService\LoginService\LoginService.svc.cs:line 74
at SyncInvokeBCryptLogin(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
这是我第一次尝试 POST 网络服务,但我很无知:S 出了什么问题?
我的测试请求如下所示:
{"login":"username","password":"password"}
(也试过)
{"LoginData":{"login":"username","password":"password"}}
LoginData 对象的定义如下:
[DataContract]
public class LoginData
{
[DataMember]
public string login { get; set; }
[DataMember]
public string password { get; set; }
}