我在休息服务方面有点新鲜
我的服务如下
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate="AuthenticateJSON/?username=username&password=password")]
public Response.Authenicate Authenticate(string username,string password)
{
var returnObject = new Authenicate();
try
{
returnObject.Response = "True";
}
catch (Exception exceptionObject)
{
returnObject.IsError = true;
returnObject.ErrorMessage = exceptionObject.Message;
}
return returnObject;
}
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate="AuthenticateJSON/?username=username&password=password")]
public Response.Authenicate Authenticate(string username,string password)
{
var returnObject = new Authenicate();
try
{
returnObject.Response = "True";
}
catch (Exception exceptionObject)
{
returnObject.IsError = true;
returnObject.ErrorMessage = exceptionObject.Message;
}
return returnObject;
}
我通过以下代码消费服务
string input = @"{'himanshu','password'}";
var newUser = new User();
newUser.username = "username";
newUser.password = "username";
var input = new JavaScriptSerializer().Serialize(newUser);
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:20620/Services/User/OperationActiveDirectory.svc/AuthenticateJSON/?username=username&password=password");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";//POST/GET
string responseText = "";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(input);//any parameter
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
responseText = streamReader.ReadToEnd();
}
但是我在执行
时面临以下错误有人可以告诉我这里我做错了吗