Use RpcLite to build SOA/Web Services (Full. Net Framework), rpclitesoa

Source: Internet
Author: User

Use RpcLite to build SOA/Web Services (Full. Net Framework), rpclitesoa

Use RpcLiteBuild SOA/WebService (Full. Net Framework)

SOA framework Series

1. Use RpcLite to build SOA/Web Services

2. Use RpcLite to build SOA/Web Services (Full. Net Framework)

 

It has been several months since the previous article "using RpcLite to build SOA/Web Services. In the past few months, RpcLite has made many changes, such as. Net Core support, Fluent API configuration, Monitor, and Filter.

 

The previous article introduced the basic usage of RpcLite. The configuration method described in this article is troublesome for the configuration file. This article uses the Fluent API method to configure. Net Core without using the configuration file. in Asp. Net, you only need to add an HttpModule.

 

Create a server

Full. Net Framework only supports Host to ASP. NET.

To create a service, follow these steps:

  • Create a Web Application project
  • Add RpcLite reference
  • Add RpcHttpModule to Web. config
  • Create a service contract Interface
  • Create a service class by implementing the service contract Interface
  • Initialize RpcLite in Global. asax
Create a Web Application project
  • Open Visual Studio 2015
  • Open the menu File creation New external Project...
  • Select Templates external Visual C # external Web from the menu on the left.
  • Select ASP. NET Web Application (. Net Framework) from the project type)
  • Make sure that the target Framework version is. NET Framework 4.0 or later.
  • Enter the project name HelloRpcLiteService. Click OK.
Add RpcLite reference

There are two ways to add a reference: directly download the dll and then reference it and add it through NuGet. It is easy to add it through NuGet. This article uses this method as an example. There are also two ways to add via NuGet: graphical interface or command line

Command Line

  • Choose Tools manage NuGet Package Manager> Package Manager Console.
  • Run Install-Package RpcLite

Graphic Interface

  • In Solution Explorer, right-click HelloRpcLite and select Manage NuGet Packages...
  • On the NuGet page, select the Browse Tab and search for RpcLite.
  • Install RpcLite in search results
Web. by default, the RpcLite package dependency is added after RpcHttpModule is added in config. config will be automatically added. If you have already added an HTTP module, ignore the operations in this section. The method for adding an HttpModule in the integrated pipeline mode is different from that in the classic pipeline mode. In this article, the most used integrated pipeline mode is described.

Add <add name = "RpcLite" type = "RpcLite. Service. RpcHttpModule, RpcLite. NetFx"/> under the configuration/system. webServer Node

The complete configuration is as follows:

<?xml version="1.0" encoding="utf-8"?><configuration>    <system.webServer>            <modules>                    <add name="RpcLite" type="RpcLite.Service.RpcHttpModule, RpcLite.NetFx" />            </modules>    </system.webServer></configuration>

 

Create a service contract Interface
  • Create a class file IProductService. cs
  • Enter the following content
namespace HelloRpcLiteService{        public interface IProductService        {                string GetDateTimeString();        }}

 

Create a service class by implementing the service contract Interface
  • Create a class file ProductService. cs
  • Enter the following content
 
using System;namespace HelloRpcLiteService{        public class ProductService : IProductService        {                public string GetDateTimeString()                {                        return DateTime.Now.ToString();                }        }}

 

Initialize RpcLite in Global. asax
  • Add Global. asax to the Project
  • Add the initialization code to the Application_Start function.
using System;using RpcLite.Config;namespace HelloRpcLiteService{        public class Global : System.Web.HttpApplication        {                protected void Application_Start(object sender, EventArgs e)                {                        RpcInitializer.Initialize(builder => builder                                .UseService<ProductService>("ProductService", "api/service/")                                .UseServicePaths("api/")                                );                }        }}

 

Description

  • UseService <ProductService> ("ProductService", "api/service/") is to add a service generic parameter ProductService to provide a class for the service, the first parameter "ProductService" is the service name "api/service/", which is the address of the service relative to the current WebApplication root. For example, the WebApplication address is http: // localhost: 8080 the service address is http: // localhost: 8080/api/service /. If the service is deployed to a virtual directory such as http: // localhost: 8080/app1, the service address is http: // localhost: 8080/app1/api/service/
  • UseServicePaths ("api/") specifies the service address prefix. All URLs starting with this address are considered as RpcLite services, and the routes used in UseService must be included in ServicePaths. If this option is not configured, the service cannot be accessed normally.
The RpcLite service has been created and can be run to view the result.
  • Run WebApplication F5 and check the address in the browser. Assume It is http: // localhost: 11651.
  • Access http: // localhost: 11651/api/service/GetDateTimeString in the browser. The returned content is the current date.
  • Access http: // localhost: 11651/api/service/in the browser to view the current service information, service name, and all interface names.
Service Name: ProductServiceActions:String GetDateTimeString();

You can access this service through the RpcLite client and JavaScript.

 

This article Code address https://github.com/aolyn/rpclite.docs/tree/master/samples/HelloRpcLite/src/HelloRpcLiteService

 

QQ: 364617712

Welcome to join

Contact info

Related Article

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.