次の方法で共有


A Walk-Through on “WCF RIA Service Toolkit May 2010” New Feature: WCF Client Proxy Auto Generation/Updating for WCF Core Service

After you install WCF RIA Services Toolkit May 2010, you will see a new feature available as highlighted in the snapshot below.

This feature enables the similar code generation for WCF Core services as WCF Domain services. The client proxy code and configuration will be automatically generated or updated when the solution is being built.

clip_image002

Let’s do a quick walk-through to better understand this feature.

WCF Client Proxy Code Auto Generating/Updating

Step 1: We create a Silverlight application using the “Silverlight Application” template, with “Enable Silverlight RIA service” option selected. The “SilverlightApplication15” solution is created which composes of “SilverlightApplication15” project as client and “SilverlightApplication15.Web” project as server.

clip_image004

Step 2: We add the “Silverlight-enabled WCF Service” item to the “SilverlightApplication15.Web”.

clip_image006

Step 3: We build the solution. We select “Show All Files” in “SilverlightApplication15” project in the Solution Explorer. We can notice a “GenerateWcfClientCode” folder is created composing of the WCF client proxy code named as “ServiceReference.cs”. We can also see the client configuration file is created named as “ServiceReferences.ClientConfig”.

clip_image008

Step 4: We can open the MainPage.xaml.cs file and write the client code to invoke the service.

clip_image010

If we make changes to service code, the client code will be updated accordingly after we build the solution.

“Add Service Reference” can work well together with this feature in the same Silverlight solution.

 

Opt out of “WCF Client Proxy Code Auto Generating/Updating”

We can manually add “<DisableAutoServiceReference/>” property in the proj file of client projects to opt out of proxy auto generation/updating. For example:

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>

     ……..

    <UsePlatformExtensions>false</UsePlatformExtensions>

    <ThrowErrorsInValidation>true</ThrowErrorsInValidation>

<LinkedServerProject>..\SilverlightApplication2.Web\SilverlightApplication15.Web.csproj</LinkedServerProject>

<DisableAutoServiceReference>true</DisableAutoServiceReference>

  </PropertyGroup>

Once we set this property to true, all the auto generated client proxy code and configuration will be removed after building the solution.

Comments