Condividi tramite


How to: Create a Provider

 

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

After you create your service contracts, you are ready to create the provider. The Provider for the chat application consists of the ProviderService object that communicates with the Object Model, and the ProviderCore object that manages the chat connections.

Before you start the procedures in this section, you should complete the procedures listed in How to: Create a Contract.

Note

You should make sure that you have copied the templates in the SDK to the ProjectTemplates folder for Visual Studio 2010.

To create the ProviderService class

  1. In the ChatSample project, add a reference to the ProviderFramework.dll file that you located when you set up the development environment.

  2. Open the ProviderService.cs file.

  3. Add the SetUserName method for identifying the user.

    private string m_userName;  
    
    public void SetUserName( string name ) {  
       m_userName = name;  
    }  
    
  4. Change the DoOperation method to represent the SendChat method.

    public void SendChat(string text) {  
       m_core.SendOperation( m_userName, text );  
    }  
    
  5. Change the SendToClient method to include the user name and text parameters.

    internal void SendToClient(string name, string text) {  
       try {  
          m_callback.ResponseReceived(name, text);  
       }  
       catch (CommunicationException) {}  
       catch (TimeoutException) {}  
    }  
    
  6. Save the project.

To create the ProviderCore class

  1. Open the ProviderCore.cs file.

  2. Change the SendOperation method to include the user name and text parameters.

    public void SendOperation(string name, string text) {  
       lock (m_syncRoot) {  
          foreach (var connection in m_connections) {  
             connection.SendToClient(name, text);  
          }  
       }  
    }  
    
  3. Save the project.

The next step is to create the host process. To do this, see How to: Create a Host Process.