WCF's internal Communications Service factory

Source: Internet
Author: User

WCF, very good, but also troublesome, many times do not want to use WCF reason is: With this really troublesome ...

Troublesome places, such as:

A heap of service configurations, scattered under one folder, error prone to update the system

The client must know the location of the service provider in addition to the WCF contract

So there is a way to simplify these, the main idea is:

Join internal communication Service, referred to as ICS. Used to insert a custom middle tier

Write a service Locator service that is used to extract WCF service provider information for unified storage, such as URL, endpoint type, WCF service provider location-Independent

When completed, WCF clients, including services that call other WCF services within the WCF service ... The calling code changes to the following ways:

Does not support the way transactions are invoked
iuser usersrv = icsfactory.create<iuser> ();
var result = Usersrv.getusername ("1", "2", 

"3");
Icsfactory.close (USERSRV);
    
    
    
Calling method that supports transactions
string result = String. Empty;
using (TransactionScope ts = new TransactionScope ())
{
      Iuser usersrv = icsfactory.create<iuser> ();
      Iadmin adminsrv = icsfactory.create<iadmin> ();
    
      result = Usersrv.getusername ("1", "2", 

"3");
      result = adminsrv.checkpermission (100). ToString ();
    
      Ts.complete ();
    
      Icsfactory.close (USERSRV);
      Icsfactory.close (ADMINSRV);
}

Configuration information for WCF clients where are we going? A: In AppSetting, there is a key that represents the path to the service configuration information file, such as: \\fs\root\a2d.service.config, the configuration file is as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<A2D>
    <ServiceLocator>
        <service Contractnamespace= "Desbinterface" 

contract= "Iuser" >
            <url endpointtype= 

"TCP" >net.tcp:// 192.168.1.100:9999/usersrv<

;/url>
        </Service>
        <service contractnamespace= " Desbinterface " 

contract=" Iadmin ">
            <url 

endpointtype=" TCP ">net.tcp://192.168.1.100:9998 /adminsrv&l

t;/url>
        </Service>
    </ServiceLocator>
</A2D>

If the client calling the WCF service has only one program, it won't be much use, but if you have a lot of client programs, that's useful, as in the following scenario:

4 servers are called as clients for WCF services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.