1
votes

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();
2
We need to know the actual exception, and where it's actually happening within the code.Andrew Barber
Enable debugging, and include the stack trace.ziesemer
You should run the local iis for this , i suggest you to turn on two Visual Studio on project is the client the other one is server, after you turn the server [CTRL+F5] you take the address of the server url like you have done.<br/> After that you go to the client and make the request, it should work.IamStalker
@ Andrew when i call from powershell,the webservice is running perfectly responding.when i call from c#,it is showing this erroruser386258
Show us the PowerShell code. It's doing something different.Roger Lipscombe

2 Answers

2
votes

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.

0
votes

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.