Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

ServiceReference Class

Registers a Web service for use in a Web page.

Syntax

CSharp

[DefaultPropertyAttribute("Path")]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class ServiceReference

VisualBasic

<DefaultPropertyAttribute("Path")> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class ServiceReference

ManagedCPlusPlus

[DefaultPropertyAttribute(L"Path")]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class ServiceReference

JSharp

/** @attribute DefaultPropertyAttribute("Path") */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class ServiceReference

Members

IconMemberDescription
ServiceReferenceNew()Initializes a new instance of the ServiceReference class.
ServiceReferenceNew(String)Initializes a new instance of the ServiceReference class with a specified path.
Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Finalize()Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode()Serves as a hash function for a particular type. (Inherited from Object.)
GetType()Gets the Type of the current instance. (Inherited from Object.)
InlineScriptGets or sets a value that indicates whether the proxy generation script is included in the page as an inline script block or is obtained by a separate request.
MemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
PathGets or sets the path of the referenced Web service.
ToString()Returns a string that represents the value of the Path property or the type name. (Overrides Object.ToString().)

Remarks

To call Web service methods from ECMAScript (JavaScript), you must include a service reference in the ASP.NET page and apply the ScriptServiceAttribute attribute to the Web service class definition. If you include a service reference to a Web service in the ScriptManager or ScriptManagerProxy control inside the ASP.NET page, JavaScript objects will be instantiated in the browser.

The proxy objects will be used to do the following:

  • Make asynchronous requests in JavaScript to Web service methods,

  • Initialize instances of proxies of server data types, in particular for use as input parameters for invoking Web methods.

note

The ServiceReference control can only be used for services in the same domain.

You can define the Web service location declaratively by adding an <asp:ServiceReference> element to the <Services> element inside the <asp:ScriptManager> element on the page, and then setting its Path attribute, as shown in the following example.

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

You might use the InlineScript property to indicate whether the proxy generation script is included in the page as an inline script block or is obtained by a separate request.

You can also programmatically add a ServiceReference object through the ScriptManager.Services or ScriptManagerProxy.Services collection by using the Add(Q) method of the ServiceReferenceCollection class.

Examples

The following example demonstrates how to add a reference to a Web service in the page markup to call the Web service methods from script.

Permissions

  • AspNetHostingPermission

    for operating in a hosted environment. Demand value: LinkDemand. Associated enumeration: Minimal.

  • AspNetHostingPermission

    for operating in a hosted environment. Demand value: InheritanceDemand. Associated enumeration: Minimal.

Inheritance Hierarchy

Object

  • ServiceReference

Assembly: System.Web.Extensions (Module: System.Web.Extensions)