Posts

Showing posts from 2011

Create a WCF service that responds to HTTP GET or HTTP POST requests

Define a basic WCF service contract with an interface marked with the ServiceContractAttribute attribute. Mark each operation with the OperationContractAttribute . Add the WebGetAttribute attribute to stipulate that an operation should respond to HTTP GET requests. You can also add the WebInvokeAttribute attribute to explicitly specify HTTP POST, or not specify an attribute, which defaults to HTTP POST. [ServiceContract] public interface IMusicService { //This operation uses a GET method. [OperationContract] [WebGet] string LookUpArtist(string album); //This operation will use a POST method. [OperationContract] [WebInvoke] void AddAlbum(string user, string album); //This operation will use POST method by default //since nothing else is explicitly specified. [OperationContract] string[] GetAlbums(string user); //Other operations omitted… } Implement the IMusicService service contract with a MusicService . public class MusicServ...

Add an ASP.NET AJAX Endpoint Without Using Configuration

Windows Communication Foundation (WCF) allows you to create a service that exposes an ASP.NET AJAX-enabled endpoint that can be called from JavaScript on a client Web site. To create such an endpoint, you can either use a configuration file, as with all other WCF endpoints, or use a method that does not require any configuration elements. This topic demonstrates the second approach. To create services with ASP.NET AJAX endpoints without configuration, the services must be hosted by Internet Information Services (IIS). To activate an ASP.NET AJAX endpoint using this approach, specify the WebScriptServiceHostFactory as the Factory parameter in the @ServiceHost directive in the .svc file. This custom factory is the component that automatically configures an ASP.NET AJAX endpoint so that it can be called from JavaScript on a client Web site. For a working example, see the AJAX Service Without Configuration . For an outline of how to configure an ASP.NET AJAX endpoint using configuration ...

Use Configuration to Add an ASP.NET AJAX Endpoint

Windows Communication Foundation (WCF) allows you to create a service that makes an ASP.NET AJAX-enabled endpoint available that can be called from JavaScript on a client Web site. To create such an endpoint, you can either use a configuration file, as with all other Windows Communication Foundation (WCF) endpoints, or use a method that does not require any configuration elements. This topic demonstrates the configuration approach. The part of the procedure that enables the service endpoint to become ASP.NET AJAX-enabled consists of configuring the endpoint to use the WebHttpBinding and to add the endpoint behavior. After configuring the endpoint, the steps to implement and host the service are similar to those used by any WCF service. For a working example, see the AJAX Service Using HTTP POST . For more information about how to configure an ASP.NET AJAX endpoint without using configuration, see How to: Add an ASP.NET AJAX Endpoint Without Using Configuration . To create a basic WCF...

Data Contracts & Serialization

Image
Introduction WCF Services and their clients depend on the exchange of data to accomplish any task. This section discusses how WCF handles data and data serialization. In general, a WCF service receives messages, processes them and sends messages back. For example, the following service contract accepts a message with information on the project name and returns a message that contains the project id: [ServiceContract] public interface IProject { [OperationContract] int GetProjectID( string projectname ) [OperationContract] void GetProjectDetails(int ID, out string manager, out DateTime dtStartDate, out DateTime dtEndDate); } Service Contracts Describing Messages This section explains the various ways in which messages can be described by an operation contract: Describing Messages Using Parameters Describing Empty Messages Describing Messages Using Message Contracts Describing Messages Using Streams Describing Messages Using Faults Describing Messages Using Derived Types Descri...