我正在尝试拨打网络服务。我收到500内部错误。 webservice正在运行。我使用以下代码
此时我收到错误:
WebResponse response = request.GetResponse();
代码:
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();
堆栈跟踪
at System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)\ r \ n在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)\ r \ n在Microsoft.VisualStudio.HostingProcess .HostProc.RunUsersAssembly()\ r \ n在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)\ r \ n在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)\ r \ n在系统中.Threading.ThreadHelper.ThreadStart()
Powershell代码
$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();
答案 0 :(得分:2)
500响应表明Web服务存在问题。您需要调试Web服务,而不是调用服务。我首先要验证你的方法是否被调用,然后从那里开始工作。
如果未调用您的Web服务,则需要验证正在发送的XML以及Web服务的URL。
答案 1 :(得分:0)
我遇到了同样的错误,WebService没有问题。问题出在我发送到服务器的XML请求中。