从控制台应用程序调用Web服务时出现内部服务器错 [英] Internal server error while calling web services from console application

查看:117
本文介绍了从控制台应用程序调用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.


这篇关于从控制台应用程序调用Web服务时出现内部服务器错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆