设为首页 加入收藏

TOP

绛河 初识WCF4(一)
2017-10-11 15:59:29 】 浏览:683
Tags:绛河 初识 WCF4

参考:

http://blog.csdn.net/anlun/article/details/44860821

第四篇 初探通信--ChannelFactory

 

通过前几篇的学习,我们简单了解了WCF的服务端-客户端模型,可以建立一个简单的WCF通信程序,并且可以把我们的服务寄宿在IIS中了。我们不禁感叹WCF模型的简单,寥寥数行代码和配置,就可以把通信建立起来。然而,仔细品味一下,这里面仍有许多疑点:服务器是如何建起服务的?我们在客户端调用一个操作后发生了什么?元数据到底是什么东西?等等。我们现在对WCF的理解应该还处于初级阶段,我们就会觉得有许多这样的谜团了。

 

虽然我们生活在WCF为我们构建的美好的应用层空间中,但是对于任何一项技术,我们都应力求做到知其所以然,对于底层知识的了解有助于我们更好的理解上层应用,因此在刚开始学习入门的时候,慢一点、细一点,我觉得是很有好处的。

 

言归正传,我们现在已经知道了一件最基本的事情,客户端和服务器是要进行通信的。那么这个通信是如何发生的呢?根据我们前面的学习,从实际操作上看,我们在服务端定义好协定和实现,配置好公开的终结点,打开元数据交换,在客户端添加服务引用,然后就直接new出来一个叫做XXXClient 的对象,这个对象拥有服务协定里的所有方法,直接调用就可以了。仔细想想?天哪,这一切是怎么发生的?!

 

服务端定义协定和实现并公开终结点,这看上去没什么问题,虽然我们对底层的实现不了解,但总归是合乎逻辑的,而客户端怎么就通过一个添加服务引用就搞定一切了呢?似乎秘密在这个添加的服务引用中。

 

打开第二篇中我们建立的客户端(如果你为第三篇的IIS服务建立了客户端,打开这个也行,我用的就是这个),看看服务引用里面有什么。

1. 服务引用初探

在解决方案浏览器中点击上方的"显示所有文件"按钮,然后展开服务引用。

这么一大堆,有一些xsd文件我们可能知道是框架描述的文档,那wsdl什么的是什么,还有disco(迪斯科?)是什么,一头雾水。

其中有一个cs文件,这个想必我们应该看得懂,打开来看看

//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.42000
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

namespace HelloWcfClent.MyService {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="MyService.IHelloWcfService")]
    public interface IHelloWcfService {
        
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHelloWcfService/HelloWcf", ReplyAction="http://tempuri.org/IHelloWcfService/HelloWcfResponse")]
        string HelloWcf();
        
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHelloWcfService/HelloWcf", ReplyAction="http://tempuri.org/IHelloWcfService/HelloWcfResponse")]
        System.Threading.Tasks.Task<string> HelloWcfAsync();
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface IHelloWcfServiceChannel : HelloWcfClent.MyService.IHelloWcfService, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class HelloWcfServiceClient : System.ServiceModel.ClientBase<HelloWcfClent.MyService.IHelloWcfService>, HelloWcfClent.MyService.IHelloWcfService {
        
        public HelloWcfServiceClient() {
        }
        
        public HelloWcfServiceClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        public HelloWcfServiceClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public HelloWcfServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public HelloWcfServiceClient(System.ServiceModel.Channels.Binding binding, System.S
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇计算机应用基础教程作业 汽车服务.. 下一篇计算机应用基础教程作业 车辆工程..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目