Building Soa/web Services with Rpclite (full. Net Framework)

Source: Internet
Author: User

using Rpclite Build Soa/web services (full. Net Framework)

SOA Framework Series

1. Building Soa/web Services using Rpclite

2. Building the Soa/web service using Rpclite (full. Net Framework)

Following the previous article, "Using Rpclite to build soa/web services" has been a few months. Many changes have been made to rpclite in the past few months, such as:. Net core Support, Fluent API configuration, Monitor, filter, and other functions.

The previous article describes the basic use of rpclite, and the configuration described in this article is cumbersome to use for configuration files. This article configures the use of the fluent API so that the configuration file is completely unused in. Net core and only needs to be added in ASP. HttpModule.

Create a service-side

The full. Net framework now supports only host to ASP.

Creating a service consists of the following steps:

    • Create a Web Application project
    • Add Rpclite Reference
    • Web. config Add rpchttpmodule
    • Create a service contract interface
    • Creating a service class by implementing a service contract interface
    • Initialize the Rpclite in Global.asax
Create a Web Application project
    • Open Visual Studio 2015
    • Open menu file? New? Project ...
    • In the left menu, select Templates? Visual C #? Web
    • To select the ASP. NET WEB application in the project type
    • Ensure that the target Framework version is. NET Framework 4.0 or higher
    • Fill in the project name Hellorpcliteservice Click OK
Add Rpclite Reference

There are two ways to add a reference: Download the DLL directly and then reference it, add it through NuGet, where it's easy to add through NuGet, as an example of this article. There are two ways to add through NuGet: The graphical interface or the command line

Command line

    • Open Menu Tools? NuGet Package Manager? Package Manager Console
    • Run Install-package Rpclite

Graphical interface

    • In Solution Explorer, right-click Hellorpclite, select Manage NuGet Packages ...
    • Select the Browse tab in the NuGet page and search for Rpclite
    • Install Rpclite in search results
Web. config add rpchttpmodule by default Add Rpclite package dependency after Web. config is automatically added, if you have automatically added ignore this section to add HttpModule mode in integrated pipe mode and classic pipe mode, this article takes the most current integrated piping module Type description

Under Configuration/system.webserver node add <add name= "Rpclite" type= "RpcLite.Service.RpcHttpModule, Rpclite.netfx"/ >

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
    • New class file IProductService.cs
    • Enter the following content
namespace hellorpcliteservice{        publicinterface  iproductservice        {                 string getdatetimestring ();        }}

Creating a service class by implementing a service contract interface
    • New class file ProductService.cs
    • Enter the following content
using System; namespace hellorpcliteservice{        publicclass  productservice:iproductservice        {                 Publicstring  getdatetimestring ()                {                        return  DateTime.Now.ToString ();         }}}

Initialize the Rpclite in Global.asax
    • Add Global.asax to your project
    • Adding initialization code to the Application_Start function
usingSystem;usingRpclite.config;namespacehellorpcliteservice{ Public classGlobal:System.Web.HttpApplication {protected voidApplication_Start (Objectsender, 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 the service provider class, the first parameter " Productservice "for service name" api/service/"is the address of the service relative to the current WebApplication root, for example the WebApplication address is http://localhost:8080 and 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 prefix of the service address, all URLs starting at this address will be considered rpclite services, and the path used in Useservice must be in servicepaths. If this option is not configured, the service cannot be accessed properly.
Run to this one Rpclite service has been created and can run to view the results.
    • F5 run WebApplication, view the address in the browser, assuming it is http://localhost:11651
    • In the browser access http://localhost:11651/api/service/GetDateTimeString, you can see that the content returned is the current date
    • In the browser access http://localhost:11651/api/service/can see the current service information, service name and all interface names
Service Name:ProductServiceActions:String getdatetimestring ();

This service can be accessed through the Rpclite client and JavaScript.

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

QQ Group: 364617712

Welcome to Join

Contact information

Building Soa/web Services with Rpclite (full. Net Framework)

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.