我试图制作一个excel下载功能。 我创建了一个webservice来序列化字符串类型的xml参数。
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string DATACRUD(string XmlParms)
{
XmlParms = System.Web.HttpUtility.UrlDecode(XmlParms);
.
.
.
.
}
我通过Ajax调用它并从Javascript中输入location.href值。
这两种方式都运行良好,直到达到在web.config中配置的maxUrl和maxQueryString。
<requestLimits maxUrl="4096" maxQueryString="4096" />
和<httpRuntime requestValidationMode="2.0" maxRequestLength="300000" maxQueryStringLength="2097151" maxUrlLength="2097151" />
导致网址看起来像这样。
localhost:/MyWebservice.asmx/DATACRUD?XmlParms={%27service%27:%27M_CUST%27,%27method%27:%27EXCEL%27,%27type%27:%27XLS%27,%27_order%27:%27M_CUST_NO%20DESC%27,%27_sort%27:%27%27,%27USITE%27:%2712%27,%27UID%27:%271000059%27,%27UKEY%27:%27F778BFB5-9920-4197-878C-8BAB6B5CF457%27,%27key%27:%270%27,%27MENUID%27:%271001%27,%27STEPMENU%27:%27%27,%27ACTIONNAME%27:%27xls%EB%8B%A4%EC%9A%B4%27,%27xlsType%27:%27report%27,%27xlsService%27:%27M_CUST%27,%27xlsMethod%27:%27undefined%27,%27dispCols%27:%27{%22dispCols%22%20:[{%20colNo:%20%220%22,%20label:%20%22%EB%B2%88%ED%98%B8%22,%20field:%20%22M_CUST_NO%22%20},{%20colNo:%20%221%22,%20label:%20%22%EC%95%84%EC%9D%B4%EB%94%94%22,%20field:%20%22%22%20},{%20colNo:%20%222%22,%20label:%20%22%EC%9D%B4%EB%A6%84%22,%20field:%20%22CUST_NAME%22%20},{%20colNo:%20%223%22,%20label:%20%22%EC%95%BD%EA%B5%AD%EB%AA%85%22,%20field:%20%22%22%20},{%20colNo:%20%224%22,%20label:%20%22%ED%9A%8C%EC%9B%90%EA%B7%B8%EB%A3%B9%22,%20field:%20%22%22%20},{%20colNo:%20%225%22,%20label:%20%22%EC%82%AC%EC%97%85%EC%9E%90%EB%B2%88%ED%98%B8%22,%20field:%20%22%22%20},{%20colNo:%20%226%22,%20label:%20%22%EA%B0%80%EC%9E%85%EA%B2%BD%EB%A1%9C%22,%20field:%20%22%22%20},{%20colNo:%20%227%22,%20label:%20%22%EC%B6%94%EC%B2%9C%EC%9D%B8%22,%20field:%20%22%22%20},{%20colNo:%20%228%22,%20label:%20%22ETC%EC%BD%94%EB%93%9C%22,%20field:%20%22%22%20},{%20colNo:%20%229%22,%20label:%20%22ETC%EB%8B%B4%EB%8B%B9MM%22,%20field:%20%22%22%20},{%20colNo:%20%2210%22,%20label:%20%22ETC%EC%82%AC%EB%AC%B4%EC%86%8C%22,%20field:%20%22%22%20},{%20colNo:%20%2211%22,%20label:%20%22OTC%EC%BD%94%EB%93%9C%22,%20field:%20%22%22%20},{%20colNo:%20%2212%22,%20label:%20%22OTC%EB%8B%B4%EB%8B%B9MM%22,%20field:%20%22%22%20},{%20colNo:%20%2213%22,%20label:%20%22OTC%EC%82%AC%EB%AC%B4%EC%86%8C%22,%20field:%20%22%22%20},{%20colNo:%20%2214%22,%20label:%20%22%ED%8F%AC%EC%82%AC%EC%BD%94%EB%93%9C%22,%20field:%20%22%22%20},{%20colNo:%20%2215%22,%20label:%20%22%ED%8F%AC%EC%82%AC%EB%8B%B4%EB%8B%B9MM%22,%20field:%20%22%22%20},{%20colNo:%20%2216%22,%20label:%20%22%ED%8F%AC%EC%82%AC%EC%82%AC%EB%AC%B4%EC%86%8C%22,%20field:%20%22%22%20},{%20colNo:%20%2217%22,%20label:%20%22%EC%95%BD%EA%B5%AD%EC%A0%84%ED%99%94%22,%20field:%20%22%22%20},{%20colNo:%20%2218%22,%20label:%20%22%ED%9C%B4%EB%8C%80%ED%8F%B0%22,%20field:%20%22%22%20},{%20colNo:%20%2219%22,%20label:%20%22%ED%9A%8C%EC%9B%90%EC%83%81%ED%83%9C%22,%20field:%20%22%22%20},{%20colNo:%20%2220%22,%20label:%20%22%ED%9A%8C%EC%9B%90%EA%B0%80%EC%9E%85%EC%9D%BC%22,%20field:%20%22%22%20},{%20colNo:%20%2221%22,%20label:%20%22%ED%9A%8C%EC%9B%90%EC%8A%B9%EC%9D%B8%EC%9D%BC%22,%20field:%20%22%22%20},{%20colNo:%20%2222%22,%20label:%20%22%EA%B0%80%EC%9E%85%EA%B5%AC%EB%B6%84%22,%20field:%20%22%22%20},{%20colNo:%20%2223%22,%20label:%20%22%EC%95%BD%EA%B5%AD%EC%A3%BC%EC%86%8C%22,%20field:%20%22%22%20},{%20colNo:%20%2224%22,%20label:%20%22%EC%9D%B4%EB%A9%94%EC%9D%BC%22,%20field:%20%22%22%20},{%20colNo:%20%2225%22,%20label:%20%22%ED%8E%98%EC%97%85%EC%9D%BC%EC%9E%90%22,%20field:%20%22%22%20},{%20colNo:%20%2226%22,%20label:%20%22%EC%B5%9C%EC%A2%85%EB%A1%9C%EA%B7%B8%EC%9D%B8%EC%9D%BC%EC%9E%90%22,%20field:%20%22%22%20}]}%27,%27structureName%27:%27CST_CUSTOMER_TBL%27}
它很冗长,我知道。
首先,我得到了404.15 error
。
然后,IIS建议我添加上面提到的requestLimits
和httpRuntime
标记。
所以我可以成功通过404.15 error
,但接下来,还有另一个陷阱。
System.NotSupportedException: System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it implements IDictionary.
at: System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo)
at: System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
at: System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
at: System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)
at: System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at: System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
at: System.Web.Services.Protocols.XmlReturnWriter.GetInitializers(LogicalMethodInfo[] methodInfos)
at: System.Web.Services.Protocols.MimeFormatter.GetInitializers(Type type, LogicalMethodInfo[] methodInfos)
at: System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at: System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at: System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
我不知道在这个阶段该做什么。
如果此url成功调用webservice,我将尝试调试,但在调用之前,它会抛出此纯文本错误消息。
从Web浏览器获取请求时,IIS或代码后面会发生什么?