从控制台应用程序调用Web服务时出现内部服务器错

从控制台应用程序调用Web服务时出现内部服务器错

问题描述:

我创建了一个Web API,我想要从外部应用程序调用Web服务,如控制台。但我收到内部服务器错误。

private void CallWebService()
    {  string licenseResposeJSON = string.Empty;
        string value = " http://vyastestapi1.azurewebsites.net/api/Employee/POSTaccount";     
                try
                {
            {
                using (WebClientEx client = new WebClientEx())
                {    
                       client.Timeout = 6000000;
                    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                    licenseResposeJSON = client.UploadString(value.ToString(), "  vaishali");
                    }
                    Console.WriteLine("Name" + licenseResposeJSON);
                    Console.ReadLine();    
            }    
                }
                catch (WebException exception)
                {
                    string str = string.Empty;
                    if (exception.Response != null)
                    {
                        using (StreamReader reader =
                            new StreamReader(exception.Response.GetResponseStream()))
                        {
                            str = reader.ReadToEnd();
                        }
                        exception.Response.Close();
                    }
                        if (exception.Status == WebExceptionStatus.Timeout)
                    {
                        throw new InvalidPluginExecutionException(                                "The timeout elapsed while attempting to issue the request.", exception);
                    }
                   }                  }        
    public class WebClientEx : WebClient
    {   public int Timeout { get; set; }
            protected override WebRequest GetWebRequest(Uri address)
        {                var request = base.GetWebRequest(address);
            request.Timeout = Timeout;
            return request   }}

错误:

"内部服务器错误"是服务器抛出任何异常时从客户端获得的。你可以从客户端调试它,除非你只是使用参数,直到找到
不会使服务器崩溃的组合。正确的做法是在服务器端使用调试器,直到找到失败的确切内容。
"Internal Server Error" is what you get from the client side when the server throws ANY exception. There isn't much that you can do to debug it from the client side, unless you just paly with the arguments until you find some combination that doesn't crash the server. The right thing to do would be to use the debugger on the server side until you locate exactly what is failing.