Condividi tramite


Building the Windows Communication Foundation Samples

The Windows Communication Foundation (WCF) samples can be built using Visual Studio 2005 or using the msbuild command from the command line. Both procedures are described in this topic.

NoteNote:

Before building or running any of the WCF samples, ensure you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.

To build the sample using a command prompt

  1. Open the SDK command prompt and navigate to the language-specific subdirectory under the directory location where you installed the sample.

  2. Type msbuild at the command line. The client program files are built to client\bin and the service program files are built to service\bin. If the service is hosted by the Internet Information Service (IIS), the service program files are also copied to the ServiceModelSamples directory and its \bin subdirectory.

NoteNote:

You must set the ACLs on %systemdrive%\inetpub\wwwroot to grant modify permissions to the account under which you are running. Otherwise some post build events fail. Alternatively, you can leave the ACLs as they are and run the SDK command prompt as administrator.

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to the language-specific subdirectory under the directory location where you installed the sample.

  2. Double-click the .sln file icon to open the file in Visual Studio.

  3. In the Build menu, select Rebuild Solution. The client program files are built to client\bin and the service program files are built to service\bin. If the service is hosted in IIS, the service program files are also copied to the ServiceModelSamples directory and its \bin subdirectory.

NoteNote:

You must set the ACLs on %systemdrive%\inetpub\wwwroot to grant modify permissions to the account under which you are running. Otherwise some post build events fail. Alternatively, you can leave the ACLs as they are and run the SDK command prompt or Visual Studio as administrator. Some Visual Studio actions (such as attaching a debugger to the ASP.Net worker process) also require administrative privileges.

Setup Batch Files and Scripts

Setup.exe and Cleanup.exe batch files and scripts should be run from the SDK command prompt. Several setup and cleanup files perform tasks that require administrative privileges and should be launched with administrator privileges.

Important Security Information about Metadata Endpoints

To prevent unintentional disclosure of potentially sensitive service metadata, the default configuration for Windows Communication Foundation (WCF) services disables metadata publishing. This behavior is secure by default, but also means that you cannot use a metadata import tool (such as Svcutil.exe) to generate the client code required to call the service unless the service’s metadata publishing behavior is explicitly enabled in configuration. To make experimenting with the samples easier, almost all samples expose an unsecured metadata publishing endpoint. Such endpoints are potentially available to anonymous unauthenticated consumers and care must be taken before deploying such endpoints to ensure that publicly disclosing a service’s metadata is appropriate. See the Metadata Publishing Behavior sample for details on publishing service metadata. See the Custom Secure Metadata Endpoint sample for a sample securing a metadata endpoint.

Exception Handling

Generally speaking these samples do not include exception handling to keep the code focused on the subject of the sample. To see details about exception handling see the Expected Exceptions sample.

Regenerating Clients and Configuration with Svcutil

You can use the ServiceModel Metadata Utility Tool (Svcutil.exe) to regenerate client code and configuration for most of the samples. Some samples require manually edited configuration. For example, if you use Svcutil.exe to regenerate the configuration for a sample that uses client certificate credentials, you must manually specify the credentials previously configured. Some samples use specific Svcutil.exe options to affect the generated code, these options are specified in the specific sample topics.

To regenerate the client and configuration files

  1. Open an SDK command prompt and navigate to the language-specific subdirectory under the directory location where you installed the sample.

  2. If the service is a Web-hosted type:

    svcutil.exe /n:"http://Microsoft.ServiceModel.Samples,Microsoft.ServiceModel.Samples" https://localhost/servicemodelsamples/service.svc/mex /out:generatedClient.cs
    

    If the service is a self-hosted type:

    svcutil.exe /n:"http://Microsoft.ServiceModel.Samples,Microsoft.ServiceModel.Samples" https://localhost:8000/servicemodelsamples/service.svc/mex /out:generatedClient.cs
    

    And replace https://localhost:8000/ServiceModelSamples/service.svc/mex with the address of the self-hosted service's mex endpoint.

    To generate the client in a Visual Basic type:

    svcutil.exe /n:"http://Microsoft.ServiceModel.Samples,Microsoft.ServiceModel.Samples" https://localhost/servicemodelsamples/service.svc/mex /l:vb /out:generatedClient.vb
    

    If the service is a self-hosted type:

    svcutil.exe /n:"http://Microsoft.ServiceModel.Samples,Microsoft.ServiceModel.Samples" https://localhost:8000/servicemodelsamples/service.svc/mex /l:vb /out:generatedClient.vb
    
    NoteNote:

    To skip the generation of client configuration add the /noConfig option.

See Also

Concepts

Running the Windows Communication Foundation Samples

Other Resources

ServiceModel Metadata Utility Tool (Svcutil.exe)

Footer image

Send comments about this topic to Microsoft.
© Microsoft Corporation. All rights reserved.