我已经使用vb.net语言开发了WCF服务;为了抛出错误,我对每个API方法执行以下操作:
Public Function UploadFiles(ByVal stream As Stream) As UploadedFiles Implements IMyRestService.UploadFiles
Try
' do something
Catch ex As Exception
Throw New WebFaultException(Of ErrMessage)(ex.Message, HttpStatusCode.BadRequest)
Finally
' do something else
End Try
最近我遇到了最大上传文件大小的问题,因此我在web.config中添加了此文件:
<configuration>
<!--other stuff-->
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
抛出的错误是404 - File or directory not found.
。但是我希望像我所有的API方法一样抛出custom ErrMessage
的WebFaultException;
而且我希望在web.config不仅在达到最大文件大小时引发错误时引发此错误,因为在<!--other stuff-->
标记中我添加了其他限制。那我该怎么做呢?