次の方法で共有


WebService.Context プロパティ

現在の要求に対する ASP.NET HttpContext を取得します。これには、HTTP サーバーが Web 要求を処理するために使用するすべての HTTP 固有のコンテキストがカプセル化されています。

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

プロパティ値

現在の要求に対する ASP.NET HttpContext

例外

例外の種類 条件
Exception Context が null 参照 (Visual Basic では Nothing) です。

解説

SoapRpcMethodAttribute 属性または SoapDocumentMethodAttribute 属性が適用されており、 OneWay プロパティが true に設定されている XML Web サービス メソッドでは、静的な Current プロパティを使用して HttpContext にアクセスしないでください。 HttpContext にアクセスするには、XML Web サービスのメソッドを実装するクラスを WebService から派生し、 Context プロパティにアクセスします。

使用例

[Visual Basic, C#] Context プロパティを使用してサーバーでの要求時刻を取得する例を次に示します。

 
<%@ 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] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

WebService クラス | WebService メンバ | System.Web.Services 名前空間 | HttpContext