当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  WCF从理论到实践四:路在何方

 WCF从理论到实践四:路在何方

点击次数:20 次 发布日期:2008-11-26 22:30:35 作者:源代码网
源代码网推荐     
源代码网推荐  
源代码网推荐  本文的出发点
源代码网推荐  
源代码网推荐  通过阅读本文,您能了解以下知识:
源代码网推荐  
源代码网推荐  Address是什么?
源代码网推荐  Address的组成?
源代码网推荐  如何在配置文件中指定Address?
源代码网推荐  如何通过编程方式设置Address?
源代码网推荐  Address有什么特殊应用?
源代码网推荐  
源代码网推荐  
源代码网推荐  本文适合的读者
源代码网推荐  
源代码网推荐  适合WCF初学者,可以没有任何SOA和其他分布式开发经验
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  Address是什么?
源代码网推荐  
源代码网推荐  一个要和服务端通讯的客户端要做的第一件事情,就是搞清数据要发给谁?目的地在哪?而Address正是通过一个Uri来唯一标示一个WCF的终节点(EndPoint)的,它标示了消息发送的目的地。在WCF 数据通讯中,它解决了服务在哪里的问题。
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  Address的组成?
源代码网推荐  
源代码网推荐  Address在WCF中的用System.ServiceModel.EndpointAddress对象来表示的,它的结构如下:
源代码网推荐  
源代码网推荐  组成部分
源代码网推荐   作用
源代码网推荐  
源代码网推荐  Uri
源代码网推荐   指示EndPoint的地址,是必须的
源代码网推荐  
源代码网推荐  Identity
源代码网推荐   能保证地址的唯一性,当Uri一致的时候,可以用Identity来区分EndPoint,可有可无
源代码网推荐  
源代码网推荐  Headers
源代码网推荐   为地址提供了一些附加信息,用于Soap Message Filter,最后会添加到Soap消息的Header中
源代码网推荐  
源代码网推荐  
源代码网推荐  此外,Address还包括IsAnonymous属性,用于指示终节点是否能匿名访问。
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  如何在配置文件中指定Address?
源代码网推荐  
源代码网推荐  在配置文件中,有两种方式可以指定Address,一种是绝对地址方式,另外是相对地址方式,分别如下:
源代码网推荐  
源代码网推荐  绝对地址
源代码网推荐  
源代码网推荐   <host>
源代码网推荐   <baseAddresses>
源代码网推荐   <add baseAddress = "http://localhost:8731/" />
源代码网推荐   </baseAddresses>
源代码网推荐   </host>
源代码网推荐   <endpoint address ="http://localhost:8731/Service" binding="basicHttpBinding" contract="Wcf_Address_Config.IService1"> </endpoint>
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  相对地址
源代码网推荐  
源代码网推荐   <host>
源代码网推荐   <baseAddresses>
源代码网推荐   <add baseAddress = "http://localhost:8731/" />
源代码网推荐   </baseAddresses>
源代码网推荐   </host>
源代码网推荐   <endpoint address ="Service1" binding="basicHttpBinding" contract="Wcf_Address_Config.IService1"></endpoint>
源代码网推荐  在网上有人说绝对地址是通过将httpGetEnabled设置为true,并且设置httpGetUrl为绝对地址是在设置endPoint的说法有些不准确,因为在WCF中有两种地址,一种是访问endPoint时候用到地址,另外一种是服务描述的地址,服务描述在wcf中被称作serviceMetadata,通过它能够产生代理类,比如,我们做如下的设置:
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8731/Service"/>
源代码网推荐  只代表在http://localhost:8731/Service/?wsdl上能找到服务描述,可以通过http://localhost:8731/Service/?wsdl生成代理类,而不是将endPoint的地址设置为了http://localhost:8731/Service,这点一定要注意,不要受有些说法的误导。
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  如何通过编程方式设置Address?
源代码网推荐  
源代码网推荐  除了能在配置中设置Address外 ,还可以通过编程的方式来设置Address,具体方法请参参见下面的代码示例:
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   static void Main(string[] args)
源代码网推荐   {
源代码网推荐   EndpointAddress address = new EndpointAddress("http://127.0.0.1:2136/Service1");
源代码网推荐   Binding binding = new BasicHttpBinding();
源代码网推荐   wcf.IService1 service = new wcf.Service1Client(binding, address);
源代码网推荐   Console.WriteLine(service.GetData(2));
源代码网推荐   Console.Read();
源代码网推荐   }
源代码网推荐  上面的代码就是将endPoint的地址设置为了http://127.0.0.1:2136/Service1
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  Address有什么特殊应用?
源代码网推荐  
源代码网推荐  在wcf中,能够将服务同时发布到几个地址上面,只要这些地址采用的都是一种访问方式。这种一份程序,多个发布地址的做法,在以往的技术中是没有的。
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  示例项目:
源代码网推荐  
源代码网推荐  通过配置文件设置Address:/Files/jillzhang/Wcf_Address_Config.rar
源代码网推荐  通过代码方式设置Address:/Files/jillzhang/Wcf_Address.rar
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  本文参考资料
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/artech/archive/2007/02/28/659331.html
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/anders-x-hu/archive/2007/05/29/763971.html
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/huangjizhou/archive/2007/12/03/981592.html
源代码网推荐  
源代码网推荐  http://www.cnblogs.com/wayfarer/archive/2007/09/26/906075.html
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华