Share via


ServiceReference 클래스

정의

웹 페이지에서 사용할 웹 서비스를 등록합니다.

public ref class ServiceReference
public class ServiceReference
type ServiceReference = class
Public Class ServiceReference
상속
ServiceReference

예제

다음 예제에서는 페이지 태그에서 웹 서비스에 대한 참조를 추가하여 스크립트에서 웹 서비스 메서드를 호출하는 방법을 보여 줍니다.

<%@ 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)에서 웹 서비스 메서드를 호출하려면 ASP.NET 페이지에 서비스 참조를 포함하고 웹 서비스 클래스 정의에 특성을 적용 ScriptServiceAttribute 해야 합니다. 웹 서비스에 ScriptManager 대한 서비스 참조를 ASP.NET 페이지 내의 컨트롤에 ScriptManagerProxy 포함하면 JavaScript 개체가 브라우저에서 인스턴스화됩니다.

프록시 개체는 다음을 수행하는 데 사용됩니다.

  • JavaScript에서 웹 서비스 메서드로 비동기 요청을 합니다.

  • 특히 웹 메서드를 호출하기 위한 입력 매개 변수로 사용하기 위해 서버 데이터 형식의 프록시 인스턴스를 초기화합니다.

참고

컨트롤은 ServiceReference 동일한 도메인의 서비스에만 사용할 수 있습니다.

다음 예제와 같이 페이지 요소 내 <asp:ScriptManager> 의 요소에 요소를 <Services> 추가 <asp:ServiceReference> 한 다음 해당 특성을 설정하여 웹 서비스 위치를 선언적으로 정의할 Path 수 있습니다.

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

InlineScript 속성을 사용하여 프록시 생성 스크립트가 페이지에 인라인 스크립트 블록으로 포함되어 있는지 또는 별도의 요청으로 가져오는지 여부를 나타낼 수 있습니다.

클래스의 ServiceReferenceCollection 메서드를 ServiceReference 사용하여 프로그래밍 방식으로 또는 ScriptManagerProxy.Services 컬렉션을 통해 ScriptManager.Services 개체를 Add 추가할 수도 있습니다.

생성자

ServiceReference()

ServiceReference 클래스의 새 인스턴스를 초기화합니다.

ServiceReference(String)

지정된 경로를 사용하여 ServiceReference 클래스의 새 인스턴스를 초기화합니다.

속성

InlineScript

프록시 생성 스크립트를 페이지에 인라인 스크립트 블록으로 포함할지 아니면 별도의 요청에 의해 가져올지를 나타내는 값을 가져오거나 설정합니다.

Path

참조되는 웹 서비스의 경로를 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetProxyScript(ScriptManager, Control)

사용자 지정으로 재정의할 수 있는 파생된 ServiceReference 개체의 프록시 스크립트를 제공합니다.

GetProxyUrl(ScriptManager, Control)

사용자 지정으로 재정의할 수 있는 파생된 ServiceReference 개체의 프록시 URL을 제공합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

Path 속성 값이나 형식 이름을 나타내는 문자열을 반환합니다.

적용 대상

추가 정보