Generating WCF Proxy using SvcUtil.exe

Visual Studio 2008 has made our WCF life a lot
easier
with the ability to self-host the services and also allow debugging
in our service.

What if we were pushed to a situation wherein we need to use the tool svcutil.exe to create our proxy for the client…hmm…

To do so, we need to have our service running. Once the service is up
and running, we could generate the proxy by the following command (replace the
tags correspondingly) :


   1: svcutil /t:code http://<service_url> 
   2:       /out:<file_name>.cs /config:<file_name>.config

Here is my example :


   1: C:\Users\Chaks\Documents\Visual Studio 2008\Projects\MyService\MyServiceHost>
   2: svcutil /t:code http://localhost:8731/Design_Time_Addresses/MyService/WcfService/ 
   3: /out:MyServiceProxy.cs /config:MyServiceProxy.config
   4: Microsoft (R) Service Model Metadata Tool
   5: [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
   6: Copyright (c) Microsoft Corporation.  All rights reserved.
   7:  
   8: Attempting to download metadata from 'http://localhost:8731/Design_Time_Addresse
   9: s/MyService/WcfService/' using WS-Metadata Exchange or DISCO.
  10: Generating files...
  11: C:\Users\Chaks\Documents\Visual Studio 2008\Projects\MyService\MyServiceHost\MyS
  12: erviceProxy.cs
  13: C:\Users\Chaks\Documents\Visual Studio 2008\Projects\MyService\MyServiceHost\MyS
  14: erviceProxy.config

Now we can add this .cs file to the Client project and copy the
.config file contents to the Client’s app.config file and
execute the client

We can also instruct svcutil to generate the proxy in the preferred language
we want :


   1: svcutil /t:code /language=VB 
   2:      http://localhost:8731/Design_Time_Addresses/MyService/WcfService/ 
   3:          /out:MyServiceProxy.vb /config:MyServiceProxy.config

 

 

ServiceModel 元数据实用工具 (Svcutil.exe)

ServiceModel 元数据实用工具用于依据元数据文档生成服务模型代码,以及依据服务模型代码生成元数据文档。

元数据:用于描述要素、数据集或数据集系列的内容、覆盖范围、质量、管理方式、数据的所有者、数据的提供方式等有关的信息。

Svcutil命令选项:

  • /async   同时生成同步和异步方法签名。默认设置:只生成同步方法签名。缩写形式:/a
  • /config:<配置文件>   为生成的配置文件指定文件名。默认设置:output.config
  • /out:<文件>   为生成的代码指定文件名。默认设置:派生自某个架构的 WSDL 定义名称、WSDL 服务名称或目标命名空间。缩写形式:/o

你可能感兴趣的:(proxy)