美文网首页
Net Core 访问 Web API,不使用IIS发布Web

Net Core 访问 Web API,不使用IIS发布Web

作者: 悟FaN | 来源:发表于2019-08-27 16:48 被阅读0次

    客户端:

    class Program

    {

    static void Main(string[] args)

    {

    DoIt();

    }

    private static void DoIt()

    {

    try

    {

    String serverUrl = "http://192.168.5.110:9090/Sum";

    System.Console.WriteLine("Please enter the first number:");

    String firstNumber = System.Console.ReadLine();

    System.Console.WriteLine("The second number:");

    String secondNumber = System.Console.ReadLine();

    System.Console.WriteLine("Enter the web api URL, or empty as default:" + serverUrl);

    String newServerUrl = System.Console.ReadLine();

    if (!String.IsNullOrEmpty(newServerUrl))

    {

    serverUrl = newServerUrl;

    }

    String responseData = HttpClientHelper.PostResponse(serverUrl, new { first = firstNumber, second = secondNumber });

    BeetleX.FastHttpApi.JsonResult responseResult = JsonConvert.DeserializeObject(responseData);

    System.Console.WriteLine("Result:" + responseResult.Data);

    }

    catch (Exception ex)

    {

    System.Console.WriteLine(ex.StackTrace);

    System.Console.WriteLine(ex.Message);

    }

    finally

    {

    System.Console.WriteLine("Continue?(Y/N):");

    String c = System.Console.ReadLine();

    if ("Y".Equals(c) || "y".Equals(c))

    {

    DoIt();

    }

    }

    }

    }

    api服务端:

    class Program

    {

    private static BeetleX.FastHttpApi.HttpApiServer mApiServer;

    static void Main(string[] args)

    {

    mApiServer = new BeetleX.FastHttpApi.HttpApiServer();

    mApiServer.Options.LogLevel = BeetleX.EventArgs.LogType.Debug;

    mApiServer.Options.LogToConsole = true;

    mApiServer.Debug();

    mApiServer.Register(typeof(Program).Assembly);

    mApiServer.Open();

    Console.Write(mApiServer.BaseServer);

    Console.Read();

    }

    }

    [Controller]

    public class Calculate : IController

    {

    [Post]

    [JsonDataConvert]

    public int Sum(int first, int second, IHttpContext context)

    {

    Console.WriteLine(context.Data);

    return first+second;

    }

    [Post]

    [JsonDataConvert]

    public object SumObject(int first, int second, IHttpContext context)

    {

    Console.WriteLine(context.Data);

    return first + second;

    }

    [NotAction]

    public void Init(BeetleX.FastHttpApi.HttpApiServer server, string path)

    {

    }

    }

    ​​

    下载链接:https://download.csdn.net/download/jasonhongcn/11619767

    交流QQ群:676208164

    相关文章

      网友评论

          本文标题:Net Core 访问 Web API,不使用IIS发布Web

          本文链接:https://www.haomeiwen.com/subject/bvoeectx.html