webserver的“text/html;charset=utf-8”,但应为“text/xml”错误
今日把添加了一个方法后的webserve重新生成后发布上去,在调用的网页使用。这时,当使用原来的老方法的引用是报出异常
“/”应用程序中的服务器错误。
--------------------------------------------
客户端发现响应内容类型为“text/html; charset=utf-8”,但应为“text/xml”。
请求失败,错误信息为:
--
<html>
<head>
<title>Parser Error</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>Parser Error</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
<br><br>
<b> Parser Error Message: </b>Could not create type 'SpService'.<br><br>
<b>Source Error:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
<font color=red>Line 1: <%@ WebService Language="C#" CodeBehind="SpService.cs" Class="SpService" %>
</font></pre></code>
</td>
</tr>
</table>
<br>
<b> Source File: </b> /spService.asmx<b> Line: </b> 1
<br><br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
</font>
</body>
</html>
<!--
[HttpParseException]: Could not create type 'SpService'.
at System.Web.UI.SimpleWebHandlerParser.GetType(String typeName)
at System.Web.UI.SimpleWebHandlerParser.GetTypeToCache(Assembly builtAssembly)
at System.Web.Compilation.SimpleHandlerBuildProvider.GetGeneratedType(CompilerResults results)
at System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results)
at System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results)
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath)
at System.Web.UI.WebServiceParser.GetCompiledType(String inputFile, HttpContext context)
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
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)
--><!--
This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
--.
源错误:
行 138: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Login", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 139: public string Login(string bname, string bcode) {
行 140: object[] results = this.Invoke("Login", new object[] {
行 141: bname,
行 142: bcode});
[解决办法]
1、在配置文件中增加以下信息
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
理由为指定传输协议,ASP.NET 可使用这些传输协议来解密 HTTP 请求中从客户端浏览器发送的数据。在对 XML Web services 的 HTTP 请求中发送的数据可以包含方法调用和参数。 上面的示例启用所有四个当前支持的协议。 (如3楼说)。
2、web服务运行过程中发生错误,如下载的文件过大,超过了服务器内存报错。(分批下载即可)
3、确认WebService的URL路径是否配置正确,确认运行环境是否正确。