【问题标题】:webService request failed with HTTP status 404webService 请求失败,HTTP 状态为 404
【发布时间】:2013-04-10 03:38:54
【问题描述】:

我在通过 webService (System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse) 发送大文件时遇到问题。

当文件小于 20 MB 时一切正常,如果文件更大,我会收到 404 代码的响应。

异常信息

Exception Type: System.Net.WebException
Status: ProtocolError
Response: System.Net.HttpWebResponse
Message: The request failed with HTTP status 404: Not Found.
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Object[] ReadResponse(System.Web.Services.Protocols.SoapClientMessage, System.Net.WebResponse, System.IO.Stream, Boolean)
HelpLink: NULL
Source: System.Web.Services

堆栈跟踪信息

   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at ie.osds.DocumentsTransferBLL.FSDMZRepositoryService.FileStreamingWebService.UploadScanning(DateTime DateCreated, String Title, String FileName, String ReferenceNumber, String Author, String DocumentType, XmlNode IndexData, Byte[] Content, Nullable`1 IsCompressed, Nullable`1 Version, DateTime DateReceived, String CreatedBy, String OrigDocumentGUID)
   at ie.osds.DocumentsTransferBLL.Actions.ActionsHelper.UploadDocumentToDMZFileStreaming(FileStreamingWebService fsDMZWebService, SPQDocument spqDocument, String documentReferenceNumber, String documentAuthor, String documentType, Byte[] documentContent, String version, DateTime dateReceived)
   at ie.osds.DocumentsTransferBLL.Actions.DocumentsUploadAction.Upload()*

【问题讨论】:

  • 你能发布一些失败的代码吗?
  • 那一刻我不能,因为我只收到记录的错误消息,我尝试解决它。这应该通过一个简单的文件流式 Web 服务和使用的方法更新。

标签: asp.net web-services http-status-code-404


【解决方案1】:

听起来你的文件上传超时了:

您可以在 global.asax 中捕获此错误以查看是否是这种情况:

Protected Sub Application_EndRequest(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim context As HttpContext = HttpContext.Current.ApplicationInstance.Context
    If Not IsNothing(context) Then

        If Not context.Response.StatusCode = HttpStatusCode.OK Then

            'Detect file upload exceeded max length:
            If context.Response.StatusCode = 404 And
                context.Response.SubStatusCode = 13 Then
                'clear the previous error page content:
                context.Response.Clear()
                'redirect to custom error page:
                context.Server.Transfer("~/error.aspx?code=404.13", False)
            End If

        End If

    End If
End Sub

您还可以像这样在 web.config 中增加请求长度:

<system.web>
    <httpRuntime maxRequestLength="29296" />
</system.web>

注意:值以千字节为单位

【讨论】:

    【解决方案2】:

    如果 Web 应用程序中有 Web 服务引用,只需将其删除,然后重新构建,运行 Web 服务,然后再次将该 Web 服务引用添加到 Web 应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 2023-01-21
      • 2011-08-02
      • 2014-05-22
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多