• WCF Basics


    1.How to install WCF
            you can locate o website: http://blogs.msdn.com/madhuponduru/archive/2006/02/22/537622.aspx
    (it 's supported only by windowsxp,2000,server2003,vista) 

    2 What is WCF(Window Communication Foundation)
        it's a programming platform and runtime system for creating network distributed services
        currently we have many separate technologies that meet specific need (Enterprise Servies, Remoting, ASMX WebServies) requiring developers to make technology choices. WCF supports all the features of these technoligies so that choice is no longer necessary.

    3 Basic Concepts

        

    4 standart bindings
        BasicHttpBinding
        WsHttpBinding
        WsDualHttpBinding
        NetTcpBinding
        NetNamedPipesBinding
        NetMsmqBinding
        NetPeerTcpBinding
        MsmqIntegrationBinding

    5 WCF Hosting
        i. IIS 
        ii. Self Host(can be any wcf client application)
        iii.windows Activation Services(WAS) hosting evvironment
        iv.NT Services.
        v. IIS hosting only supports HTTP proctocol
        vi.WAS supports all protocols.

    6 Why we have to recommed customer to hst WCF apps in IIS
        i. since asp.net supports health monitoring support, it's better ot host in IIS
        ii.since IIS is designed for large scale apps, performance is lot better when u host WCF apps in IIS

    7 WCF key words 
        [servicecontract]
        [operationcontract]
        [servicebehaviour]
        [operationbehavious]

    8. How to use WCF tools
        i.svcutil.exe
        ii.svcconfigeditor.exe
        iii.svctraceviewer.exe

    9.How to write simple WCF client/server app
        i.server side
           >create a class library project called HelloSvc, and add the reference with system.ServiceModel;

    using ...*
    using system.ServiceModel;
     name space HelloSvc
     {
        [ServiceContract]
        public interface IHello
        {
            [ServiceOperation]
            string SayHello();
        }    
        public class HelloSvc:IHello
        {
            public string SayHello()
                {
                    return "Hello World";
                }

                //to selft-host WCF service
                public static void main()
                {
                    uri baseAddress=new uri(http://localhost:8081/testsvc);
                    ServiceHost sh=new ServiceHost(typeof[HelloSvc],baseAddress);
                    sh.Open();
                    Console.WriteLine("service is ready for calls");
                    Console.ReadLine();
                 }
        
        }
     }

          >then we create a configuration xml file named app.config to configurate the WCF
          the following
            <?xml version="1.0" encoding="utf-8">
            <configuration>
                <system.serviceModel>
                    <services>
                        <service name="HelloSvc.HelloSvc"  behaviorConfiguration="ManualWCF.MyServiceType">
                            <endpoint address=http://localhost:8081/testsvc binding ="wsHttpBinding" contract="HelloSvc.IHello">
                            </endpint>
                        </service>
                    </services>
                 <behaviors>
                      <serviceBehaviors>
                        <behavior name="ManualWCF.MyServiceType">
                          <serviceMetadata httpGetEnabled="true"/>
               </behavior>
          </serviceBehaviors>
        </behaviors>

                </system.serviceModel>
            </configuration>

            >re-configurate the project property of output type as application console. and then press Debug to run this application.
            In everything goes well, we can see the following screen:


    Congratulations! you have host a WCF services on Server side. then what u need to do It's to let the client side to invoke your service.  ok, next we will create another project on client side to call the services which is supplied through the address :http://localhost:8080/testsvc.

        >client side
            we create a another console/ windows/web application(either is ok) to call the services
            i.we must search the service through UDDI. because we know each service is deployed by WSDL.  having found the service , we need to add as reference.  and the it will populate client codes exposing it's contract/Interface to client side  for client program  to call. There are 2 methods to populate this client codes
              Method  1: use svcutil.exe to generate the client code automatically (ServerClient.cs & output.config)
                    the grammar is just like the following, in console model, we can keyin
                    svcutil http://localhost:8080/testsvc 
                    then ServerClient.cs and output .config will be populated.
                    and then we add this two fill to our client project. that's ok.
                Method 2:through UDDI to find the service, and then add as an reference
                    in this case, the VS.Net tool will make a new fodler under the project fodler named services reference and generate code aotomatically named references.cs  and other configuration files in which. and In the file of references.cs, there is a class named [Server%]Client from which  you can invoked all the operations from 
                the following is the repective codes:
                using System.ServiceModel;
                name space clientUsingWCF
                {
                    ServerClient sc=new ServerClient();
                    string result=sc.SayHello();
                    Console.WriteLine(result);
                    Console.Readline();
                 }

              and if every works well, then at client side you will see such result:

    congratulations!


      
  • 相关阅读:
    全文检索原理
    UBER的故事
    grails 优缺点分析
    微博轻量级RPC框架Motan
    基于redis 实现分布式锁的方案
    eggjs中cache-control相关问题
    mysql导入导出数据
    jenkins项目用户权限相关
    jenkins+gogs,服务随代码更新
    js/nodejs导入Excel相关
  • 原文地址:https://www.cnblogs.com/Winston/p/1130891.html
Copyright © 2020-2023  润新知