0

我已经编写了自己的 Web 服务,它可以独立运行。我正在从另一个页面调用此 Web 服务,当时它返回 500 Internal Server 错误。我第一次经历这个过程,不知道这意味着什么或为什么会发生这种情况。在 Google 上进行的初步搜索显示了广泛的答案,尽管我找不到任何具体的答案。

这是我的呼叫代码-

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);
        }
    }
4

2 回答 2

0

调试此问题的最佳方法可能是将 Visual Studio 附加到 IIS(菜单调试/附加到进程...),以便您可以逐步查看 Web 服务代码中发生的情况。

于 2012-04-24T22:16:36.887 回答
0

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

于 2012-04-25T17:28:18.943 回答