Web服务响应返回500内部服务器错误

时间:2012-04-24 21:01:34

标签: c# asp.net wcf web-services internal-server-error

我已经编写了自己的网络服务,它可以很好地独立工作。我从另一个页面调用此Web服务,此时它返回500内部服务器错误。我是第一次经历这个过程,不知道这意味着什么或为什么会发生这种情况。谷歌的初步搜索显示了广泛的答案,虽然我找不到任何具体的答案。

继承我的主叫代码 -

List<string> inputList = new List<string>();
inputList.Add("F");
inputList.Add("B");    
List<string> resultList = new List<string>();
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/Helpers/MyService.asmx");
httpWebRequest.Headers.Add("SOAPAction", "\"http://tempuri.org/GetOutput\"");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
JavaScriptSerializer serializer = new JavaScriptSerializer();

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    string json = serializer.Serialize(inputList);
    streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); *****ERROR HERE

string responseText = String.Empty;
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    responseText = streamReader.ReadToEnd();
}
resultList = serializer.Deserialize<List<string>>(responseText);

继承我的网络服务代码 -

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class MyService: System.Web.Services.WebService
{        
    public string GetOutput(string jsonStr)
    {
        try
        {
            /*code to format jsonStr and send it along to another web service*/

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            string responseText = String.Empty;
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                responseText = streamReader.ReadToEnd();
            }

            //this obj has a head & body
            ResponseObj response_obj = new ResponseObj();                
            response_obj = serializer.Deserialize<ResponseObj>(responseText);                
            List<string> Values = new List<string>();
            if (response_obj.head.result)
                return serializer.Serialize(response_obj.body);

            return "";                  
        }
        catch (Exception ex)
        {
               throw new Exception(ex.Message);
        }
    }

2 个答案:

答案 0 :(得分:0)

也许最好的调试方法是将Visual Studio连接到IIS(菜单调试/附加到Process ...),这样您就可以逐步查看Web服务代码中发生的事情。

答案 1 :(得分:-1)

我读到你可以在localhost / statistics / log上看到错误的详细信息,这表明我的Web.config文件存在问题。我评论了上面提到的行,错误消失了,为下一行做好了!