快速访问WCF服务--ServiceModel 元数据实用工具 (Svcutil.exe)
2014-01-14 17:36
281 查看
基本定义
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
相关文章推荐
- 快速创建WCF服务和svcutil.exe工具使用
- 利用svcutil.exe 访问windows Server 2003的wcf服务生成客户端代码报错:无法从http://XXX/XXX.svc?wsdl获取元数据”错误的解决方法
- 利用svcutil.exe 访问windows Server 2003的wcf服务生成客户端代码报错:无法从http://XXX/XXX.svc?wsdl获取元数据”错误的解决方法
- WCF 服务IIS部署 SvcUtil.exe 工具文件地址 及 生成代理类命令
- ServiceModel 元数据实用工具 (Svcutil.exe)
- WCF 服务IIS部署 SvcUtil.exe 工具文件地址 及 生成代理类命令
- WCF 服务IIS部署 SvcUtil.exe 工具文件地址 及 生成代理类命令
- 动态调用WCF不添加服务(svcutil.exe)
- wcf的svcutil.exe工具生成代码的奇怪问题
- 关于wcf三大工具的使用(wsdl.exe svcutil.exe disco.exe)
- WCF服务通过 SvcUtil.exe 方式调用,WCF半动态调用
- WCF基础_使用svcutil.exe 工具来生成调用文件
- 服务跟踪查看器工具 (SvcTraceViewer.exe)-WCF --http://blogs.msdn.com/wcftoolsteamblogcn/
- WCF 添加服务失败。服务元数据可能无法访问。请确保服务正在运行并且正在公开元数据
- Silverlight跨域访问WCF服务
- 局域网跨机访问WCF服务出错本机访问正常的问题
- Svcutil.exe – Generate the proxy class for the WCF client application
- WCF 第五章 导出并发布元数据(服务行为)
- 【实用工具】google访问不了比较好的解决办法
- WCF---当前已禁用此服务的元数据发布错误