GithubHelp home page GithubHelp logo

alexanderbuts / xmlrpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from horizon0156/xmlrpc

0.0 1.0 0.0 147 KB

This project targets to port Charles Cook's XML-RPC library to .NET Standard / .NET Core.

License: Other

C# 100.00%

xmlrpc's Introduction

Horizon.XmlRpc

This project targets to port Charles Cook's XML-RPC library to .NET Standard / .NET Core. XML-RPC.NET is a library for implementing XML-RPC Services and clients in the .NET environment

XML-RPC.NET, the port and the extensions are released under the terms of the MIT license. See License information to get further information.

Installation

All libraries are available on nuget.org

Ported components

The library, respectively its main components were ported to .NET Standard while only implementing required changes concerning the access to changed Framwork components. Therefore, the API hasn't changed. In addition, the library was refactored into three dedicated assemblies.

  • Horizon.XmlRpc.Core Holds all the core members and contracts required by a XML-RPC servive as well as a XML-RPC client
  • Horizon.XmlRpc.Client
    Holds the ported XmlRpcProxyGen, the IXmlRpcProxyinterface and their dependencies
  • Horizon.XmlRpc.Server
    Holds the ported XmlRpcListenerService, the documentation generator and their dependencies used to host a XML-RPC service in any .NET Standard compatible application.

Added components

  • Horizon.XmlRpc.AspNetCore
    Provides a middleware to host a XML-RPC service in an ASP.NET Core application

Examples

This section gives you a brief introduction on how to write a service and how to consume the service with a generated client proxy.

To get a full example of running client and server in a .NET Core application, please have a look at the Demos in the repository.

First define a contrat for your service. This will be used by the client proxy and implemented from the service.

using Horizon.XmlRpc.Core;

public interface IAddService
{
    [XmlRpcMethod("Demo.addNumbers")]
    int AddNumbers(int numberA, int numberB);
}

Then define your service and start a new listener. To host the service with ASP.NET Cores please refer to the end of the documentation.

using Horizon.XmlRpc.Server;

public class AddService : XmlRpcListenerService, IAddService
{
    public int AddNumbers(int numberA, int numberB)
    {
        return numberA + numberB;
    }
}

var service = new AddService();
var listener = new HttpListener();
listener.Prefixes.Add("http://127.0.0.1:5678/");
listener.Start();

while (true)
{
    var context = listener.GetContext();
    service.ProcessRequest(context);
}

To consume the service, simply create a client proxy and use the contract to call its methods. The service also provides an automatically generated documentation by browing to the opened enpoint http://127.0.0.1:5678/

using Horizon.XmlRpc.Client;

public interface IAddServiceProxy : IXmlRpcProxy, IAddService
{
}

var proxy = XmlRpcProxyGen.Create<IAddServiceProxy>();
proxy.Url = "http://127.0.0.1:5678";

var result = proxy.AddNumbers(3, 4);
Console.WriteLine("Received result: " + result);

// Prints 7 to the output

Hosting XML-RPC services with ASP.NET Core

To use host service with ASP.NET Core simply reference the corresponding library and let the service inherit from XmlRpcService. Then register the services and define a route to one ore more XmlRpcServices.

public class AddService : XmlRpcService, IAddService
{
    public int AddNumbers(int numberA, int numberB)
    {
        return numberA + numberB;
    }
}

Within your startup class configure the service and register required dependencies. You can also inject dependencies within your service. The underlying service factory will make use of the service container.

public void ConfigureServices(IServiceCollection services)
{
    services.AddXmlRpc();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseXmlRpc(config => config.MapService<AddService>("xml-rpc"));
}

Navigate to http://localhost:5000/xml-rpc to show the documentation or connect your XML-RPC client.

For more information about XML-RPC refer to http://www.xmlrpc.com/

xmlrpc's People

Contributors

horizon0156 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.