快速访问WCF服务--ServiceModel 元数据实用工具 (Svcutil.exe)

基本定义

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

SvcUtil.exe

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

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

  

  这里对应的不同的系统版本以及内部的.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

 

 

转载于:https://www.cnblogs.com/bjlhx/p/3519503.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值