我似乎已经找到了问题,但不知道如何修复它,或者我是否可以。
当我创建新的C# WebAPI
项目,并添加System.Net.Http
的导入时,我可以访问
Request.CreateResponse<T>
。
当我创建新的VB.Net WebAPI
项目并为System.Net.Http
添加导入时,我所拥有的只是Request.createODataErrorResponse
。
CreateResponse
。似乎VB并没有正确解释各种扩展。
我想修复intellisense,但实际上并不需要它。
谢谢!
史蒂夫
更新 我在2012年8月找到了这个forum post的答案,说明它已被复制,但似乎尚未解决。
我是新来的,应该关闭吗?
答案 0 :(得分:0)
有一种解决方法
我提出了以下解决方案:
CreateResponse2
方法CreateResponse
Request.CreateResponse2(...)
)以下是我的解决方案:
创建新模块HttpRequestMessageExtensions
Imports System.Net
Imports System.Net.Http
Imports System.Web
Imports System.Runtime.CompilerServices
Imports System.Web.Http
Public Module HttpRequestMessageExtensions
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value)
End Function
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T, Configuration As HttpConfiguration) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value, Configuration)
End Function
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T, mediaType As String) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value, mediaType)
End Function
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T, formatter As Formatting.MediaTypeFormatter) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value, formatter)
End Function
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T, mediaType As Headers.MediaTypeHeaderValue) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value, mediaType)
End Function
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T, formatter As Formatting.MediaTypeFormatter, mediaType As String) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value, formatter, mediaType)
End Function
<Extension()> _
Public Function CreateResponse2(Of T)(ByVal request As HttpRequestMessage, statusCode As HttpStatusCode, value As T, formatter As Formatting.MediaTypeFormatter, mediaType As Headers.MediaTypeHeaderValue) As HttpResponseMessage
Return request.CreateResponse(Of T)(statusCode, value, formatter, mediaType)
End Function
End Module
控制器中的用法:
Return Request.CreateResponse2(Of SomeClass)(HttpStatusCode.BadRequest, objSomeClass)
<强>截图:强>