What is Websharp Service Locator
For multi-tier application Systems, we usually divide them into clients, application services, and databases. At the application service level, we need to consider at least two issues:
• How to implement business logic
• How to provide services to clients.
We may use a variety of technologies to implement service delivery: Webservice,. Net Remoting, and even ejbs. With so much implementation technology, it brings a lot of flexibility, but it also brings problems, one of which is how many server-side technologies are available, and how many corresponding client access technologies are available. Even in some distributed application systems, the application logic is developed using different technologies, exist on different machines, some exist in the client computer, some use the. Net remoting, exist in the LAN, some use Web Service on the Internet, and sometimes We want the same business logic to support different clients.
In this case, we need a consistent service access programming model to simplify the development and deployment of the system by integration of different service access patterns. The Websharp service Locator (WSL) provides the ability for developers to define a service provider only to access these services in a consistent manner without regard to the differences between these services. The framework automatically generates the agents needed to access the remote service.
Websharp is a new open source project on SourceForge, with the goal of providing one. NET environment, it contains three main content: an O/R mapping Framework, an AOP framework, and a service Locator. Service Locator Currently only completes the initial development of the local assembly locator, the WebService locator, and the. Net Remoting Locator, but we can use the framework features it provides to help us with our development. Websharp Service Locator The following goal is to achieve the visit to Java EE. All source code can be downloaded from http://www.sourceforge.net/projects/websharp/.
Main interface of Websharp Service locator
WSL is a lightweight framework that is very easy to use and extend. If you want to use WSL, then only one class needs to be dealt with: Servicelocator, which is defined as follows:
Public abstract class Servicelocator
{
public static Object Findservice (String Servicename,type clientinterface)
}
If you want to extend the framework with your own locator, then only one interface needs to be extended: Iservicelocator. This interface is very simple, there is only one way:
Then, in the Websharp.enterprise section, register a different service locator. If you expand the framework yourself, add a new service locator and register here. Where the locator property is in the format: "Class full name, assembly name." The service locator is singleton. The following is information about the registration of the service locator currently supported by WSL:
Finally, in the Services section under Websharp.enterprise, register each service. The attributes required for each service depend on the implementation of different locator, but name, Service-type, and Deploy-model are required. For Deploy-model, you can have two property values: Singleton and multiinstance.
Note: For a configuration file, in a Web project, you can be a Web.config file, and for Windows projects you can add a app.config profile for your project yourself. For more information about. NET project profiles, refer to the MSDN documentation.
How do I use the Websharp service Locator?
The general approach to using WSL is this:
1. Define an interface that is consistent with the service you need to access (of course, if your service is implementing an interface, you can use that interface directly). The method name and parameters of an interface must be consistent with the method name and parameters of the service class. If your method name and service's method name are inconsistent, you can use Servicemethodnameattribute to indicate the method name of the service.
2. Register the service you need to access in the profile press.
3. Call the Servicelocator Findservice method.
4. Call the method of the interface.
Here are some examples of these examples that are developed using Visual Studio.NET 2003 and can also be downloaded from SourceForge.
Localassemblylocator's Hello World example
Follow these steps:
1. Create a Windows Console project named "Enterpriseclient" and add a reference to Websharp.dll.
2. Add a class named "HelloWorld" and add a method named "Gethello" with the following code:
public class HelloWorld
{
public string Gethello (string hello)
{
return hello;
}
}
3. Add an interface called "Ihelloworld" with the following code:
("Helloworldwebservice", typeof (Ihello)) as Ihello;
Console.WriteLine (Hello1. HelloWorld ());
Console.ReadLine ();
}
6. Run the program to get the following results:
Summary
With WSL, we can use a consistent programming model to access different types of services, simplifying software development and deployment. For example, we can start by using a local assembly to develop the software, and then easily change to use WebService to publish the service and turn the software into multi-tier applications. We can also use WSL to enable the same services to support different clients, and all clients use the same programming model.
Websharp is a framework that is still in the development phase, but because he is open source, we can use him directly for further development. Currently WSL support services are not many, implementation is also relatively simple, but he provides a good framework and build a distributed application program, in the future, he will provide more and more features.
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.