ServiceReference クラス

定義

Web ページで使用できるように Web サービスを登録します。

public ref class ServiceReference
public class ServiceReference
type ServiceReference = class
Public Class ServiceReference
継承
ServiceReference

次の例では、Web サービスへの参照をページ マークアップに追加して、スクリプトから Web サービス メソッドを呼び出す方法を示します。

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  
    <head id="Head1" runat="server"> 
        <style type="text/css">
            body {  font: 11pt Trebuchet MS;
                    font-color: #000000;
                    padding-top: 72px;
                    text-align: center }
  
            .text { font: 8pt Trebuchet MS }
        </style>  
        <title>Calling Web Methods</title>    
    </head>
    
    <body>
        <form id="Form1" runat="server">
        
            <asp:ScriptManager runat="server" ID="scriptManagerId">
                <Scripts>
                    <asp:ScriptReference Path="Scripts.js" />
                </Scripts>
                <Services>
                    <asp:ServiceReference  Path="WebService.asmx" />
                </Services>                
            </asp:ScriptManager>
            
            <div>
                <h2>Calling Web Methods</h2>
                 
               <table>
                    <tr align="left">
                        <td>Method that does not return a value:</td>
                        <td>
                            <!-- Getting no retun value from 
                            the Web service. --> 
                            <button id="Button1"  
                                onclick="GetNoReturn()">No Return</button>
                        </td>
                    </tr>
                    
                    <tr align="left">
                        <td>Method that returns a value:</td>
                        <td>
                            <!-- Getting a retun value from 
                            the Web service. --> 
                            <button id="Button2" 
                                onclick="GetTime(); return false;">Server Time</button>
                        </td>
                   </tr>
                   
                   <tr align="left">
                        <td>Method that takes parameters:</td>
                        <td>
                            <!-- Passing simple parameter types to 
                            the Web service. --> 
                            <button id="Button3" 
                                onclick="Add(20, 30); return false;">Add</button>
                        </td>
                       
                    </tr>
                   
                    <tr align="left">
                        <td>Method that returns XML data:</td>
                        <td>   
                             <!-- Get Xml. --> 
                            <button id="Button4" 
                                onclick="GetXmlDocument(); return false;">Get Xml</button>
                        </td>
                    </tr>
                    <tr align="left">
                        <td>Method that uses GET:</td>
                        <td>   
                             <!-- Making a GET Web request. --> 
                            <button id="Button5" 
                                onclick="MakeGetRequest(); return false;">Make GET Request</button>
                        </td>
                    </tr>
                    
                </table>
         
            </div>
        </form>
        
        <hr/>
        
        <div>
            <span id="ResultId"></span>
        </div>   
        
    </body>
    
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  
    <head id="Head1" runat="server"> 
        <style type="text/css">
            body {  font: 11pt Trebuchet MS;
                    font-color: #000000;
                    padding-top: 72px;
                    text-align: center }
  
            .text { font: 8pt Trebuchet MS }
        </style>  
        <title>Calling Web Methods</title>    
    </head>
    
    <body>
        <form id="Form1" runat="server">
        
            <asp:ScriptManager runat="server" ID="scriptManagerId">
                <Scripts>
                    <asp:ScriptReference Path="Scripts.js" />
                </Scripts>
                <Services>
                    <asp:ServiceReference  Path="WebService.asmx" />
                </Services>                
            </asp:ScriptManager>
            
            <div>
                <h2>Calling Web Methods</h2>
                 
               <table>
                    <tr align="left">
                        <td>Method that does not return a value:</td>
                        <td>
                            <!-- Getting no retun value from 
                            the Web service. --> 
                            <button id="Button1"  
                                onclick="GetNoReturn()">No Return</button>
                        </td>
                    </tr>
                    
                    <tr align="left">
                        <td>Method that returns a value:</td>
                        <td>
                            <!-- Getting a retun value from 
                            the Web service. --> 
                            <button id="Button2" 
                                onclick="GetTime(); return false;">Server Time</button>
                        </td>
                   </tr>
                   
                   <tr align="left">
                        <td>Method that takes parameters:</td>
                        <td>
                            <!-- Passing simple parameter types to 
                            the Web service. --> 
                            <button id="Button3" 
                                onclick="Add(20, 30); return false;">Add</button>
                        </td>
                       
                    </tr>
                   
                    <tr align="left">
                        <td>Method that returns XML data:</td>
                        <td>   
                             <!-- Get Xml. --> 
                            <button id="Button4" 
                                onclick="GetXmlDocument(); return false;">Get Xml</button>
                        </td>
                    </tr>
                    <tr align="left">
                        <td>Method that uses GET:</td>
                        <td>   
                             <!-- Making a GET Web request. --> 
                            <button id="Button5" 
                                onclick="MakeGetRequest(); return false;">Make GET Request</button>
                        </td>
                    </tr>
                    
                </table>
         
            </div>
        </form>
        
        <hr/>
        
        <div>
            <span id="ResultId"></span>
        </div>   
        
    </body>
    
</html>

注釈

ECMAScript (JavaScript) から Web サービス メソッドを呼び出すには、ASP.NET ページにサービス参照を含め、 属性を ScriptServiceAttribute Web サービス クラス定義に適用する必要があります。 ASP.NET ページ内の または ScriptManagerProxy コントロールに ScriptManager Web サービスへのサービス参照を含めた場合、JavaScript オブジェクトはブラウザーでインスタンス化されます。

プロキシ オブジェクトを使用して、次の操作を行います。

  • JavaScript から Web サービス メソッドへの非同期要求を行います。

  • 特に Web メソッドを呼び出すための入力パラメーターとして使用するために、サーバー データ型のプロキシのインスタンスを初期化します。

注意

コントロールは ServiceReference 、同じドメイン内のサービスにのみ使用できます。

次の例に示すように、ページの 要素内<asp:ScriptManager>の 要素に要素を<Services>追加<asp:ServiceReference>し、そのPath属性を設定することで、Web サービスの場所を宣言的に定義できます。

<asp:ScriptManager runat="server" ID="scriptManager">  
  <Services>  
    <asp:ServiceReference Path="~/WebServices/SimpleWebService.asmx" />  
  </Services>  
</asp:ScriptManager>  

プロパティを InlineScript 使用して、プロキシ生成スクリプトがインライン スクリプト ブロックとしてページに含まれているか、別の要求によって取得されるかを示します。

クラスの メソッドをServiceReference使用して、 または ScriptManagerProxy.Services コレクションをScriptManager.Services使用してオブジェクトをAddプログラムで追加ServiceReferenceCollectionすることもできます。

コンストラクター

ServiceReference()

ServiceReference クラスの新しいインスタンスを初期化します。

ServiceReference(String)

指定されたパスで、ServiceReference クラスの新しいインスタンスを初期化します。

プロパティ

InlineScript

プロキシ生成スクリプトをインライン スクリプト ブロックとしてページ内に含めるか、別の要求によって取得させるかを示す値を取得または設定します。

Path

参照する Web サービスのパスを取得または設定します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetProxyScript(ScriptManager, Control)

カスタマイズとしてオーバーライド可能な派生 ServiceReference オブジェクトからプロキシ スクリプトを提供します。

GetProxyUrl(ScriptManager, Control)

カスタマイズとしてオーバーライド可能な派生 ServiceReference オブジェクトからプロキシ URL を提供します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

Path プロパティまたは型名の値を表す文字列を返します。

適用対象

こちらもご覧ください