我正在处理表单,它通过post和显示结果将输入发送到webservice。它必须简单,并且在localhost上工作正常。但是当我尝试再次使用它时,我有错误500。
这是我的代码:
WebRequest request = WebRequest.Create("http://localhost:3192/WebServices/Export.asmx/" + uxAction.SelectedValue);
UTF8Encoding encoding = new UTF8Encoding();
byte[] data = encoding.GetBytes(uxRequest.Text);
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.ContentLength = data.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Flush();
requestStream.Close();
WebResponse response = request.GetResponse();
Stream newStream = response.GetResponseStream();
byte[] responseArray = new byte[response.ContentLength];
newStream.Read(responseArray, 0, (int)response.ContentLength);
newStream.Close();
uxResponse.Text = encoding.GetString(responseArray);
以下是有关错误的信息
Exception information:
Exception type: InvalidOperationException
Exception message: Request format is unrecognized for URL unexpectedly ending in '/GetProjectTypes'.
Request information:
Request URL: http://sitename.com/WebServices/Export.asmx/GetProjectTypes
Request path: /WebServices/Export.asmx/GetProjectTypes
User host address: 93.73.249.242
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 1
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我也有http处理程序从javascript访问Web服务,这很好用:
<add verb="GET,HEAD,POST*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
这是我的请求数据。无论是否有例外都是一样的。 Web服务没有任何参数
<?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>
<GetProjectTypes xmlns="http://sitename.com/WebServices/Export.asmx" />
</soap:Body>
</soap:Envelope>
答案 0 :(得分:0)
当我们在浏览器中测试webservice时,它会将方法名称添加到url,但是当我们发布时,这不是必需的。 我删除了'/“+ uxAction.SelectedValue',现在一切正常