zoukankan      html  css  js  c++  java
  • 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 8)

    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
  • 相关阅读:
    Netty入门
    hashCode方法里为什么选择数字31作为生成hashCode值的乘数
    【转】String hashCode 方法为什么选择数字31作为乘子
    NppFTP小插件的使用
    事务的基础入门
    Code Review 程序员的寄望与哀伤【转载】
    谈谈敏捷开发【转载】
    如何写代码 — 编程内功心法【转载】
    面经【转载】
    Swagger的简单入门【转载】
  • 原文地址:https://www.cnblogs.com/anorthwolf/p/2337337.html
Copyright © 2011-2022 走看看