次の方法で共有


How to: Create a Contract

 

Applies To: Windows Server 2012 Essentials, Windows Home Server 2011, Windows Storage Server 2008 R2 Essentials, Windows Small Business Server 2011 Essentials

You should start to develop a provider by identifying the functionality that you want to present to the home or small business network. The contracts that you define should be consumed through the object model. It is important that you understand the functionality of your object model and how it will be called by users to make sure that you have a usable contract interface. For more information about how to create contracts, see Designing Service Contracts (https://go.microsoft.com/fwlink/?LinkId=164847). The contracts for the chat application are defined as C# interfaces.

Note

Before you start the procedures in this section, you should complete the procedures listed in How to: Create an Object Model.

To create the service contract

  1. In the ChatSample.ObjectModel project, open the IProvider.cs file.

  2. Change the interface to include the SetUserName and the SendChat operations.

    [ProviderEndpointBehavior(CredentialType.User)]  
    [ServiceContract(CallbackContract = typeof(IProviderCallback))]  
    public interface IProvider {  
       [OperationContract(IsOneWay = true)]  
       void SetUserName(string name);  
    
       [OperationContract(IsOneWay = true)]  
       void SendChat(string text);  
    }  
    
  3. Save the project.

To create the callback contract

  1. In the ChatSample.ObjectModel project, open the IProviderCallback.cs file.

  2. Change the ResponseReceived operation to include the user name and text parameters.

    [ServiceContract]  
    public interface IProviderCallback {  
       [OperationContract(IsOneWay = true)]  
       void ResponseReceived(string user, string text);  
    }  
    
  3. Save the project.

The next step is to create the provider. To do this, see How to: Create a Provider.