.net 프레임 워크를 사용하여 웹 서비스를 테스트하기 위해 작은 응용 프로그램을 만들려고합니다. 서버에서 항상 오류 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의 경우 : 서버의 오류 세부 사항을 검사하십시오. –
이러한 오류 메시지는 검색 및 복사 - 붙여 넣기가 훨씬 쉬워 지므로 이미지가 아닌 텍스트로 게시하십시오. –
SOAPAction은'Addition'으로 설정되어 있습니다. 실제 SOAP 몸체는'HelloWorld'를 인자로 가지지 만 서버 메소드는'getAccount'입니다. 이 세 가지가 일치하지 않는 한 결코 작동하지 않습니다. –