我想做一個小應用程序來測試使用.net框架的Web服務。 我總是從服務器得到錯誤500。網站響應總是返回錯誤500
這裏是我的代碼 首先在服務器端代碼
public class BalanceInquiry : System.Web.Services.WebService
{
[WebMethod]
public string getAccount(string accNbr)
{
return accNbr;
}
}
這裏是我的客戶端代碼:
class Program
{
static void Main(string[] args)
{
//creating object of program class to access methods
Program obj = new Program();
Console.WriteLine("Please Enter Input values..");
//Reading input values from console
string a =(Console.ReadLine());
// int b = Convert.ToInt32(Console.ReadLine());
//Calling InvokeService method
obj.InvokeService(a);
}
public void InvokeService(string a)
{
//Calling CreateSOAPWebRequest method
HttpWebRequest request = CreateSOAPWebRequest();
XmlDocument SOAPReqBody = new XmlDocument();
//SOAP Body Request
SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body>
<getAccount xmlns=""http://tempuri.org/"">
<accNbr>" + a + @"</accNbr>
</getAccount>
</soap:Body>
</soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stream))
{
stmw.Write(SOAPReqBody);
}
}
try
{
//Geting response from request
WebResponse response = request.GetResponse();
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
Console.Read();
}
public HttpWebRequest CreateSOAPWebRequest()
{
//Making Web Request
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://localhost:62325/BalanceInquiry.asmx");
//SOAPAction
Req.Headers.Add("SOAPAction:http://tempuri.org/");
//Content_type
Req.ContentType = "text/xml;charset=\"utf-8\"";
Req.Accept = "text/xml";
//HTTP method
Req.Method = "POST";
//return HttpWebRequest
return Req;
}
}
誤差
System.Net.WebException: The remote server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse() at consumeWebSer.Program.InvokeService(String a) in C:\Users\msaliba\Documents\Visual Studio 2010\Projects\consumeWebSer\consumeWebSer\Program.cs:line 53
有沒有人有任何想法可以導致此錯誤。這是我的代碼中的東西,還是可能是別的?
至於_every_ error 500 ever:檢查服務器上的錯誤詳細信息。 –
請將這些錯誤消息作爲文本發佈,而不是圖片,因爲它使搜索和複製粘貼更容易。 –
SOAPAction設置爲'Addition',實際的SOAP主體具有'HelloWorld'作爲參數,但服務器方法是'getAccount'。只要三個不匹配,這將永遠不會工作。 –