2011-02-08 11 views
0

현재 동일한 프로젝트 내에 웹 서비스를 포함하고있는 웹 응용 프로그램 프로젝트가 있습니다. 현재 웹 서비스를 비동기 적으로 호출해야한다는 요구 사항이 있습니다. 동일한 프로젝트 내에서 웹 참조로 웹 서비스를 추가하지 않았기 때문에 위임자를 사용하여 웹 서비스 메서드를 호출하려고했는데 "HttpContext를 사용할 수 없다는 예외가 있습니다.이 클래스는 다음과 같은 상황에서만 사용할 수 있습니다. ASP.NET 요청 "웹 서비스 메서드 호출에서 응용 프로그램 속성에 액세스하려고 할 때.HttpContext를 사용할 수 없습니다 - 웹 서비스를 비동기로 호출

Web Method in MyWebServices Class 
Public Function ProcessRequest() As Boolean 
    If Application(STRING_KEY) Is Nothing Then 'Exception happens here' 
    Return True 
    Else 
    Return False 
    End If 
End Sub 

.ASPX Codebehind File 
Public Delegate Function ProcessRequestDelegate() As Integer 

Protected Sub btnSender_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sender.Click 
    Dim del As ProcessRequestDelegate 
    del = New ProcessRequestDelegate(AddressOf ProcessRequest) 
    del.BeginInvoke(null, null) 
End Sub 

Protected Function ProcessRequest() As Boolean 
    Dim services As MyWebService 
    services = New MyWebService() 
    Return services.ProcessRequest() 
End Function 

내가 여기서하려는 것은 비동기 적으로 웹 메서드를 호출하는 올바른 방법일까요?

덕분에, Javid

답변

1

웹 서비스 클래스는 웹 참조를 통해 액세스해야하며, 방법이 ProcessRequest은 WebMethod 특성으로 장식한다.

동일한 프로젝트 또는 다른 프로젝트에서 웹 서비스를 일반 클래스로 사용하는 경우 웹 서버를 거치지 않는 일반 클래스 라이브러리 인 것처럼 HttpContext.Current 객체가 null입니다.

관련 문제