zoukankan      html  css  js  c++  java
  • 快速访问WCF服务--ServiceModel 元数据实用工具 (Svcutil.exe)

    基本定义

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

    SvcUtil.exe

    ServiceModel 元数据实用工具可在 Windows SDK 安装位置中找到,具体位置为 C:Program FilesMicrosoft SDKsWindowsv6.0Bin

    在这里你可以有多个选择。

      

      这里对应的不同的系统版本以及内部的.net版本,可以调用针对不同的.net framework 版本的SvcUtil.exe.

    根据服务元数据生成 WCF 客户端

      进入SvcUtil.exe所存放的路径:

      执行>svcutil.exe http://172.168.0.112:8081/test.svc /language:cs /out:ssss.cs  (SvcUtil.exe wcf路径 )

      这里要注意的是SvcUtil.exe后面是服务的地址,会在工具所在的目录下生成代理类文件、web.config文件;

      把这个代理类拷贝到客户端程序就可以对WCF进行调用了。

      程序中调用:
                IServiceTest ist = new ServiceTestClient();//这里可以使用不同的构造方法,以方便WCF入口点
                string retValue=ist.TestParas1("测试");

      但是要增加一下wcf入口点

        1.直接使用构造方法(找到合适入口点构造方法)

              public ServiceTestClient(string endpointConfigurationName) : base(endpointConfigurationName)
              {    }
       
              public ServiceTestClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress)
              {    }
       
              public ServiceTestClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress)
              {    }
       
              public ServiceTestClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress)
              {    }

        2.配置web.config

          根据生成的配置文件修改<basicHttpBinding>、<endpoint>节点。

    元数据模型还有很多应用,详细见:http://msdn.microsoft.com/zh-cn/library/aa347733(v=vs.100).aspx

     

  • 相关阅读:
    你还在钟情于windows XP吗?
    我常用的vim快捷键
    2013年读的书(很多还没看完)
    期末考试了
    顺着自己的心,去做自己喜欢的事
    关于最近新闻泛滥的几点看法以及学习的个人观点
    华为OJ_1
    【Android】弹出软键盘时候让上面布局跟着上移的方法
    【Android】策略模式封装百度地图路线规划模块
    google觉得好用的插件(不断更新)
  • 原文地址:https://www.cnblogs.com/bjlhx/p/3519503.html
Copyright © 2011-2022 走看看