잊지 않겠습니다.

WCF Elements

.NET Framework 2009. 1. 7. 11:29

1. Contracts

  • Service Contract
  • Data Contract
  • Fault Contracts
  • Message Contract 

OperationContract : 반드시 Method에서만 구현 가능하다. 이는 WCF Model에서의 제약조건으로 가지고 있으며, 동작에 의해서 구현되는 모델의 기본 사양이 된다. (property 또는 index, value에서는 절대로 구현할 수 없다.) 

1) Hosting

  • WCF Service는 반드시 Host Process 안에서 구현되어야지 된다.
  • Hosting 방법으로는 IIS를 이용하거나, Windows Application Service(WAS)를 이용하여 배포 가능하다.
A. IIS Hosting
  • ASMX web service와 유사한 방법. .svc를 만들어서, 배포(.asmx와 거의 동일하다.)
B. Self-Hosting
  • ServiceHost와 web.config(app.config)를 이용한 hosting. Program적으로 Hosting이 가능하다.
C. WAS Hosting

 

2. Binding

1) Basic binding
  • BasicHttpBinding 
  • legacy ASMX webservice
2) TCP binding
  • NetTcpBinding
  • Cross machine communication on the internet
  • optimized for WCF-WCF communication
3) Peer network binding
  • NetPeerTcpBinding
  • using all subscribe to the same grid and broadcast message
4) IPC binding
  • NetNamedPipeBinding
  • same machine communication
  • secure binding
5) Web Service binding
  • WSHttpBinding
  • http, https
6) Federated WS binding
  • WSFederationHttpBinding
  • supported federated security
7) Duplex WS binding
  • WSDualHttpBinding 
  • supported bidirectional communication
8) MSMQ binding
  • NetMsmqBinding 
9) MSMQ integration binding
  • MsmqIntegrationBinding
  • converts WCF message to and from MSMQ message
  • for legacy MSMQ client

3. EndPoints

  • an address : where the service is
  • binding : how to communicate with the service
  • contract : what the service does

The endpoint is the fusion of the address, contract and binding

Configuration : hosting process' config file.

              <endpoint
                address ="http://localhost/WCFProduct"
                binding="basicHttpBinding"
                contract="WCFProduct.IProduct"
                />

Programmatic Endpoint Configuration

      productsServiceHost = new ServiceHost(typeof(ProductServiceImpl));
      BasicHttpBinding binding = new BasicHttpBinding();
      productsServiceHost.AddServiceEndpoint(typeof(WCFProduct.IProduct), binding, "http://localhost:8000/WCFProduct");
      productsServiceHost.Open(); 

 

4. Metadata Exchange

HTTP-GET protocol을 이용한 metadata의 제공

WebService에서의 web browser를 이용한 Method view와 비슷한 내용을 제공한다.



Metadata Exchange Endpoint

기본적으로 제공되는 Metadata exchange endpoint가 아닌, special endpoint를 제공 가능.

 

5. Clint-Side Programming

1) IDE : Using "Add Service Reference" then add service url

2) SvcUtil : SvcUtil.exe (URL) /out:outputFileName.cs

  • make a class then make the client configuration file required to interact with a service
  • write service configuration with <system.serviceModel> <client> </client> </system.serviceModel> 
         <client>
            <endpoint address="http://localhost:8000/WCFProduct" binding="basicHttpBinding"
                bindingConfiguration="NewBinding0" contract="WCFProduct.IProduct"
                name="HttpHost">
                <identity>
                    <certificateReference storeName="My" storeLocation="LocalMachine"
                        x509FindType="FindBySubjectDistinguishedName" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:8000/WCFProduct" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IProduct" contract="WCFProduct.IProduct"
                name="BasicHttpBinding_IProduct" />
        </client>

3) Generating the client config file

svcutil.exe http://localhost:8002/MyService /out:proxy.cs /config:app.config 

4) Closing the proxy

      //Method 1 : Declare open and close
      client.Open(); //Open proxy
      client.ListProducts();
      client.Close(); //Close proxy

      //Method 2 : use using statement
      using ( client  = new WCFCLient.WCFProduct.ProductClient())
      {
        client.ListProducts();
      }

      //Method 3 : Use IDisposable interface
      IDisposable disposable = client as IDisposable;
      if ( disposable != null )
      {
        disposable.Dispose();
      }

5) Programmatic Client Configuration

      //Declare endpoint address with URL
      EndpointAddress endpointAddress = new EndpointAddress("http://localhost/WCFProduct/Service.svc");
      //Declare Binding method : http, https, tcp ....
      WSHttpBinding wsBinding = new WSHttpBinding();
      WCFProduct.ProductClient client = new WCFCLient.WCFProduct.ProductClient(wsBinding, endpointAddress);

 

6. Programmatic VS. Administrative Configuration

Administrative configuration

  • the option to change major aspects of the service and the clinet post-deployment
  • it's not type safe
  • configuration error will only be discovered at runtime

Programmatic configuration

  • be able to make an entire configurateion
  • decision is static and never changed. (it's hard-cording)
Posted by Y2K
,