Export (0) Print
Expand All

WebService.Context Property

Gets the ASP.NET HttpContext for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests.

[Visual Basic]
Public ReadOnly Property Context As HttpContext
[C#]
public HttpContext Context {get;}
[C++]
public: __property HttpContext* get_Context();
[JScript]
public function get Context() : HttpContext;

Property Value

The ASP.NET HttpContext for the current request.

Exceptions

Exception Type Condition
Exception Context is a null reference (Nothing in Visual Basic).

Remarks

XML Web service methods that have either the SoapRpcMethodAttribute or SoapDocumentMethodAttribute attribute applied to them with the OneWay property of set to true, do not have access to their HttpContext using the static Current property. To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.

Example

[Visual Basic, C#] The Example below uses the Context property to obtain the time of the request on the server.

[Visual Basic] 
<%@ WebService Language="VB" Class="Util" %>
 
Imports System
Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    <WebMethod(Description := "Returns the time as stored on the Server", _
        EnableSession := False)> _
    Public Function Time() As String
        
        Return Context.Timestamp.TimeOfDay.ToString()
    End Function
End Class
 

[C#] 
<%@ WebService Language="C#" Class="Util" %>
 
 using System;
 using System.Web.Services;
 
 public class Util: WebService {
   [ WebMethod(Description="Returns the time as stored on the Server",
   EnableSession=false)]
   public string Time() {
      return Context.Timestamp.TimeOfDay.ToString();
   }
 }
 

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

WebService Class | WebService Members | System.Web.Services Namespace | HttpContext

Show:
© 2014 Microsoft