我正在开发一个 android 应用程序,并试图通过 web 服务发送数据。由于某种原因,我的 WCF 没有以 JSON 格式发送数据,我已将绑定设置为 webHttpBinding, ResponseFormat = WebMessageFormat.Json
这是我的 IService 代码:
[OperationContract]
[WebInvoke(
Method = "POST",
UriTemplate = "LoginMobile",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
LoginCredentials GetLogin(LoginCredentials Lc);
[DataContract]
public class LoginCredentials
{
[DataMember(Name = "AccountID")]
public string AccountID
{
get;
set;
}
[DataMember(Name = "NRIC")]
public string NRIC
{
get;
set;
}
[DataMember(Name = "Password")]
public string Password
{
get;
set;
}
}
我的服务:
public LoginCredentials GetLogin(LoginCredentials credentials)
{
string strConnectionString = ConfigurationManager.ConnectionStrings["PCSDB"].ConnectionString;
string strCommandText = "Select AccountID from Account Where NRIC=@NRIC AND Password=@Password";
using (SqlConnection sqlConnection = new SqlConnection(strConnectionString))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = new SqlCommand(strCommandText, sqlConnection))
{
sqlCommand.Parameters.AddWithValue("@NRIC", credentials.NRIC);
sqlCommand.Parameters.AddWithValue("@Password", credentials.Password);
int queryResult = sqlCommand.ExecuteNonQuery();
SqlDataReader reader = sqlCommand.ExecuteReader();
if (reader.Read())
{
credentials.AccountID = reader["AccountID"].ToString();
return credentials;
}
else
{
credentials.AccountID = "0";
return credentials;
}
}
}
}
请帮我!一整天都在这!