webService请求失败,HTTP状态为404

时间:2013-04-17 11:36:19

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

我在通过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

StackTrace信息

   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()*

2 个答案:

答案 0 :(得分:0)

听起来您的文件上传已超时:

您可以在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>

注意:值以千字节为单位

答案 1 :(得分:0)

如果Web应用程序中存在Web服务引用,则只删除然后重建,运行Web服务,然后再将该Web服务引用添加到Web应用程序。