Reputation: 1953
I am trying to call a webservice. I am getting 500 internal error. webservice is running .I uses the following code
I am getting the error at this point:
WebResponse response = request.GetResponse();
Code:
string requestxml = @"C\request.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(requestxml);
StringWriter sw = new StringWriter();
XmlTextWriter tx = new XmlTextWriter(sw);
xmlDoc.WriteTo(tx);
byte[] bytes = Encoding.UTF8.GetBytes(sw.ToString());
WebRequest request = WebRequest.Create("http://localhost:3993/test.asmx");
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(sw.ToString());
request.ContentType = "application/xml";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
stack trace
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()
Powershell code
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
$webRequest = [System.Net.WebRequest]::Create("http://localhost:3993/test.asmx");
$webRequest.Method = "POST";
$webRequest.ContentType = "text/xml";
$con = Get-Content .\Request.xml;
$bytes = [System.Text.Encoding]::UTF8.GetBytes($con);
$webRequest.ContentLength = $bytes.Length;
$ReqStream = $webRequest.GetRequestStream();
$ReqStream.Write($bytes,0,$bytes.Length);
#$ReqStream.Flush();
$ReqStream.Close();
$response = $webRequest.GetResponse();
Upvotes: 1
Views: 18256
Reputation: 55
I had the same error and it was not problem the WebService. The problem was in the XML request that i was sending to the server.
Upvotes: 0
Reputation: 13561
The 500 response indicates there is a problem in the webservice. You need to debug the webservice, not the call to the service. I would first verify that your method is being called, and then work on from there.
If your webservice is not being called, then you need to verify the XML that is being sent, and the URL for the webservice.
Upvotes: 2