[英]Web Service Response returns a 500 Internal Server Error
I have written my own web service which works fine stand alone. 我已经编写了自己的Web服务,可以独立运行。 I'm calling this web service from another page, and at that time it returns a 500 Internal Server error.
我从另一个页面调用此Web服务,当时它返回500 Internal Server错误。 I'm going through this process for the 1st time and do not know what this means or why this happens.
我第一次经历这个过程,不知道这意味着什么或为什么会发生。 A preliminary search on Google shows a wide range of answers, although I couldnt find anything specific.
在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);
}
}
调试的最佳方法也许是将Visual Studio附加到IIS(菜单调试/附加到Process ...),以便您可以逐步了解Web服务的代码中发生了什么。
I read that you can see details of the error at localhost/statistics/log, which showed me that there was an issue with my Web.config file. 我读到您可以在localhost / statistics / log上看到错误的详细信息,这表明我的Web.config文件存在问题。 I commented the mentioned lines and the error went away making way for the next!
我评论了上面提到的几行,错误消失了,为下一条提供了方便!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.