zoukankan      html  css  js  c++  java
  • WCF 附录 高级主题 从元数据创建客户端

    MetadataResolver类允许使用程式而不是使用配置文件来收集绑定信息。这意味着客户端可以动态创建而不需要确定一个配置文件。如果你想部署客户端然后再改服务的配置的话那么这个很有用。列表A.1 显示了如何使用MetadataResolver类来指向一个已知的元数据终结点的例子。MetadataResolver类的Resolve方法用来创建绑定信息。绑定信息包含了一个或多个ServiceEndpoint实例。每个可用的终结点都有一个ServiceEndpoint实例。ServiceEndpoint实例用来创建一个客户端。
    列表A.1 使用MetadataResolver类
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void GetPriceButton_Click(object sender, EventArgs e)
            {
                Type typeOf = typeof(ISimpleStockService);
                Uri metadataUri = new Uri("http://localhost:58609/SimpleStockService.svc/mex");
                EndpointAddress metadataAddress = new EndpointAddress(metadataUri);
                ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeOf, metadataAddress);
                string symbol = SymbolTextBox.Text;
                decimal price;
    
                foreach (ServiceEndpoint point in endpoints)
                {
                    if (point != null)
                    {
                        using (ChannelFactory<ISimpleStockService> cf = 
                            new ChannelFactory<ISimpleStockService>(point))
                        {
                            ISimpleStockService client = cf.CreateChannel();
                            price = client.GetQuote(symbol);
                            SymbolPricesListBox.Items.Insert(0, symbol + "=" + price.ToString());
                        }
                    }
                }
            }
        }
    
  • 相关阅读:
    maven Spring MVC项目
    NET 解析HTML代码——NSoup
    Masstransit开发基于消息传递的分布式应用
    iOS项目生成通用Windows应用
    测试框架mochajs详解
    9宫格拼图
    spring 整合redis
    Linux下SSH Session复制
    File Templates for web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)
    极度简约 最小 Linux 发行版 Tiny Core Linux 7.1 发布
  • 原文地址:https://www.cnblogs.com/danielWise/p/2078751.html
Copyright © 2011-2022 走看看