在C#中使用休息服务时出现内部服务器错误

时间:2013-12-05 05:37:30

标签: c# rest

我在休息服务方面有点新鲜

我的服务如下

 [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();
        }

但是我在执行enter image description here

时面临以下错误

有人可以告诉我这里我做错了吗

0 个答案:

没有答案