ASP.NET Web フォーム クライアントの作成
XML Web サービス クライアントとして機能する ASP.NET Web フォームは、プロキシ クラスの参照方法と配置方法に関して、他の XML Web サービス クライアントとは異なります。特に、Web フォームを含む Web アプリケーションの \Bin ディレクトリに配置されるアセンブリ内のパブリック クラスは、ASP.NET Web フォームから作成できます。したがって、XML Web サービス クライアントのプロキシ クラスを作成し、そのプロキシ クラスをコンパイルしてアセンブリを生成してから、\Bin ディレクトリに配置する場合、ASP.NET Web フォームではそのプロキシ クラスのインスタンスを作成できます。
XML Web サービスの Web フォーム クライアントを作成するには
XML Web サービスに対するプロキシを作成します。
Wsdl https://www.contoso.com/Counter.asmx?WSDL [Visual Basic] Wsdl /language:VB https://www.contoso.com/Counter.asmx?WSDL
詳細については、「XML Web サービス プロキシの作成」を参照してください。
この XML Web サービスのプロキシをコンパイルして、System.XML.dll アセンブリ、System.Web.Services.dll アセンブリ、手順 1 で作成したプロキシを含むアセンブリを生成します。
csc /out:Counter.dll /t:library /r:System.XML.dll /r:System.Web.Services.dll Counter.cs [Visual Basic] vbc /out:Counter.dll /t:library /r:System.XML.dll,System.Web.Services.dll Counter.vb
Web フォームを作成します。
Web フォームの作成の詳細については、「Web フォーム ページ」を参照してください。
Web フォーム内のクライアント コードでプロキシ クラスのインスタンスを作成します。
Counter myCounter = new Counter(); [Visual Basic] Dim myCounter As New Counter()
XML Web サービス メソッドと通信するプロキシ クラスのメソッドを呼び出します。
UsageCount = myCounter.ServiceUsage(); [Visual Basic] UsageCount = myCounter.ServiceUsage()
Web フォームを配置します。Web フォームを配置する Web アプリケーションの \Bin ディレクトリに XML Web サービスのプロキシのアセンブリを配置します。
Web フォームの配置の詳細については、「アプリケーションの配置」を参照してください。
上の XML Web サービスの Web フォーム クライアントを次のコード例に示します。
<%@ Page Language="C#" %> <asp:Label id="Label1" runat="server" /> <script runat=server language=c#> void Page_Load(Object o, EventArgs e){ int UsageCount; // Create an instance of the XML Web service class. Counter myCounter = new Counter(); // Call the XML Web service method ServiceUsage. UsageCount = myCounter.ServiceUsage(); Label1.BackColor = System.Drawing.Color.DarkSlateBlue; Label1.ForeColor = System.Drawing.Color.Gold; Label1.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset; // Display the results in a Label Web Form server control. if (UsageCount == 1) Label1.Text ="XML Web service has been utilized >" + UsageCount.ToString() + "< time."; else Label1.Text= "XML Web service has been utilized >" + UsageCount.ToString() + "< times."; } </script> [Visual Basic] <%@ Page Language="VB" %> <asp:Label id="Label1" runat="server" /> <script runat=server language="VB"> Sub Page_Load(o As Object, e As EventArgs) Dim UsageCount As Integer ' Create an instance of the XML Web service class. Dim myCounter As New Counter() ' Call the XML Web service method ServiceUsage. UsageCount = myCounter.ServiceUsage() Label1.BackColor = System.Drawing.Color.DarkSlateBlue Label1.ForeColor = System.Drawing.Color.Gold Label1.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset ' Display the results in a Label Web Form server control. If UsageCount = 1 Then Label1.Text = "XML Web service has been utilized >" & UsageCount.ToString() & "< time." Else Label1.Text = "XML Web service has been utilized >" & UsageCount.ToString() & "< times." End If End Sub </script>