WebService服务器帮助
服务端
- 首先使用IServiceCollection.AddWebServices注册服务及其实现。
- 使用IApplicationBuilder.UseRouting()应用路由中间价。
- 调用IApplicationBuilder.UseWebServiceEndpoint方法应用中间件。
客户端
- 调用WebServiceClient.CreateWebServiceClient方法创建客户端。T为服务端应以的协议接口,返回T协议对应的通信实现。
实例
服务端:
    /// <summary>
    /// Web服务协议
    /// </summary>
    [ServiceContract]
    public interface IWebSvc
    {
        [OperationContract]
        public string HellowWorld(string name);
    }
    public class WebSvc:IWebSvc
    {
        public string HellowWorld(string name) {
            return $"Hellow world {name}!";
        }
    }
    using Falcon.SugarApi.WebService;
    using Server;
    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddWebService<IWebSvc,WebSvc>();
    var app = builder.Build();
    app.UseRouting();
    app.UseWebServiceEndpoint<IWebSvc>("/WebService.asmx");
    app.Run();
客户端:
    using System.ServiceModel;
    [ServiceContractAttribute(ConfigurationName = "Service.IWebSvc")]
    internal interface IWebSvc
    {
        [OperationContractAttribute(Action = "http://tempuri.org/IWebSvc/HellowWorld",ReplyAction = "http://tempuri.org/IWebSvc/HellowWorldResponse")]
        Task<string> HellowWorldAsync(string name);
    }
    using Falcon.SugarApi.WebService;
    var svc = WebServiceClient.CreateWebServiceClient<IWebSvc>("http://localhost:5000/WebService.asmx");
    var result=await svc.HellowWorldAsync("Jeck");