The remote server returned an error: (500) Internal Server Error
<p>I am trying to call a webservice. I am getting 500 internal error.
webservice is running .I uses the following code</p>

<p>I am getting the error at this point:</p>

<pre><code>WebResponse response = request.GetResponse();
</code></pre>

<p>Code:</p>

<pre><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();
</code></pre>

<p>stack trace</p>

<p>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()</p>

<p>Powershell code</p>

<pre><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();
</code></pre>
