WebServiceAttribute.Namespace プロパティ
XML Web サービスで使用する既定の XML 名前空間を取得または設定します。
Public Property Namespace As String
[C#]
public string Namespace {get; set;}
[C++]
public: __property String* get_Namespace();public: __property void set_Namespace(String*);
[JScript]
public function get Namespace() : String;public function set Namespace(String);
プロパティ値
XML Web サービスで使用する既定の XML 名前空間。既定値は DefaultNamespace プロパティで指定します。
解説
XML 名前空間を使用すると、URI (Uniform Resource Identifier) で識別される名前を XML ドキュメント内に作成できます。XML 名前空間を使用すると、XML ドキュメント内の要素または属性を一意に識別できます。XML Web サービスの [サービスの説明] は、XML、特に WSDL (Web Services Description Language) で定義されます。
XML Web サービスの [サービスの説明] では、XML Web サービスに直接関係する XML 要素の既定の名前空間として、 Namespace が使用されます。たとえば、XML Web サービスの名前とその XML Web サービス メソッドは、 Namespace プロパティで指定された名前空間に関係しています。WSDL 固有の要素は、https://schemas.xmlsoap.org/wsdl/名前空間に関係しています。
XML Web サービスを呼び出すために SOAP を使用した XML Web サービス クライアントの場合は、オプションで SoapDocumentMethodAttribute または SoapRpcMethodAttribute を追加して XML Web サービス メソッドを呼び出すことができます。クライアントが ASP.NET で作成された XML Web サービスを呼び出すと、既定では、 RequestNamespace 、 ResponseNamespace 、 Action の各プロパティはすべて Namespace プロパティから派生します。たとえば、XML Web サービス メソッド名が Time
で Namespace プロパティが https://www.contoso.com/
の場合、 Action プロパティの既定値は https://www.contoso.com/Time
です。XML Web サービス メソッドの RequestNamespace 、 ResponseNamespace 、および Action の既定の設定を変更するには、 SoapDocumentMethodAttribute を XML Web サービス メソッドに追加します。
メモ Microsoft .NET Framework SDK の観点では、XML 名前空間は、クラスが存在する名前空間とは異なります。C# でプログラムを記述する場合に、クラスの名前空間を指定する方法については、「 9. 名前空間 」を参照してください。
使用例
[Visual Basic, C#] Namespace を https://www.contoso.com
に設定し、 Time
XML Web サービス メソッドに SoapDocumentMethodAttribute を追加して Action プロパティの名前空間をオーバーライドする例を次に示します。
<%@ WebService Language="VB" class= "ServerVariables"%>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Description := "Server Variables", _
Namespace := "https://www.contoso.com/")> _
Public Class ServerVariables
Inherits WebService
<SoapDocumentMethod(Action := "https://www.contoso.com/Time"), _
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= "ServerVariables"%>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
[ WebService(Description="Server Variables",
Namespace="https://www.contoso.com/")]
public class ServerVariables: WebService {
[ SoapDocumentMethod(Action="https://www.contoso.com/Time")]
[ 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 ファミリ
参照
WebServiceAttribute クラス | WebServiceAttribute メンバ | System.Web.Services 名前空間 | DefaultNamespace | SoapDocumentMethodAttribute | RequestNamespace | ResponseNamespace | Action | SoapRpcMethodAttribute