zoukankan      html  css  js  c++  java
  • wcf1

    我的理解wcf是webservice的升级版
    就是部署在另外的机器上的一个函数
    我的水平是简单应用阶段 我觉得这个阶段也就够了
    首先在vs2010建立wcf服务应用程序
    自动生成接口文件和svc文件
    如果想写一个方法
    分别在接口文件和svc文件写方法
    [OperationContract]
    string GetDate();

    public string GetDate()
    {
    return DateTime.Now.ToShortDateString();
    }

    之后随便建一个项目
    添加服务器引用
    配置文件中会自动添加如下配置
    <bindings>
    <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
    useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None"
    realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
    </binding>
    </basicHttpBinding>
    </bindings>
    <client>
    <endpoint address="http://localhost:61230/Service1.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
    name="BasicHttpBinding_IService1" />
    </client>


    封装方法的时候用如下代码
    public static string GetDate()
    {
    Service1Client client = new Service1Client();
    string s = client.GetDate();
    return s;
    }

    如果想在别的项目里面应用GetDate方法
    需要把那段xml配置粘贴到别的项目的配置文件中 也就是client.GetDate();方法只是与那段带endpoint的xml耦合。

    简单的wcf就是如此应用,指不定以后微软又研究出什么东西呢,只要wcf的东西在工作中够用就成了,除非你觉得这种纯文字的东西有意思,要不为什么非得研究的那么深呢。
  • 相关阅读:
    Linux进阶之Linux中的标准输入输出
    PermCheck
    FrogRiverOne
    PermMissingElem
    FrogJmp
    TapeEquilibrium
    恒生电子长沙2016实习生笔试题
    接口和抽象类的异同点?
    C#实现二叉树
    C#实现栈和队列
  • 原文地址:https://www.cnblogs.com/frog2008/p/2354319.html
Copyright © 2011-2022 走看看