我正在开发 WCF 应用程序,我正在调用此操作
[ServiceContract]
public interface IAuditDataService
{
[OperationContract(Name = "UserAuthentication")]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "/UserAuthentication?username={username}")]
string UserAuthentication(string username, UserData userInfo);
}
我收到错误
"Object Reference not set to an instance"
这里
public string UserAuthentication(string username, UserData userInfo)
{
string outputData = string.Empty;
return userInfo.ToString(); // << Error at this line
}
这是 JSON 类
[DataContract]
[Serializable()]
public class UserData
{
[DataMember(Name = "UserName", Order = 1)]
public string UserName { get; set; }
[DataMember(Name = "Password", Order = 2)]
public string Password { get; set; }
[DataMember(Name = "Token", Order = 3)]
public string Token { get; set; }
}
这是通过 POST 方法的 JSON 请求
{"UserName":"abcd",
"Password":"1234",
"Token":"1234"}
这是响应屏幕截图
任何帮助!