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
  • 相关阅读:
    让Windows Server 2008 + IIS 7+ ASP.NET 支持10万个同时请求
    C#多线程锁定全局变量
    ASP.NET 防止F5刷新页面按钮重复提交
    子线程调用窗体控件
    asp.net 转成XML后在SQL操作XML的值
    Sql中字符串的循环截取(用循环实现输入键串能输出值串)
    大数据量分页存储过程
    函数相关概念,及练习
    js循环(while循环,do while循环,for循环)相关知识点及练习
    parseInt()和Number()的应用区别
  • 原文地址:https://www.cnblogs.com/anorthwolf/p/2337337.html
Copyright © 2011-2022 走看看