修改WebService说明

This commit is contained in:
falcon 2023-02-16 15:38:44 +08:00
parent c9c3211c45
commit 368fdd5ddd

View File

@ -2,13 +2,14 @@
### 服务端 ### 服务端
1. 首先使用IServiceCollection.AddWebServices注册服务及其实现。 1. 首先定义协议及其实现。
2. 使用IApplicationBuilder.UseRouting()应用路由中间价。 2. 使用IServiceCollection.AddWebServices注册服务及其实现。
2. 使用IApplicationBuilder.UseRouting()应用路由中间件。
3. 调用IApplicationBuilder.UseWebServiceEndpoint方法应用中间件。 3. 调用IApplicationBuilder.UseWebServiceEndpoint方法应用中间件。
### 客户端 ### 客户端
1. 调用WebServiceClient.CreateWebServiceClient<T>方法创建客户端。T为服务端应以的协议接口返回T协议对应的通信实现。 1. 调用WebServiceClient.CreateWebServiceClient泛型方法创建客户端。泛型为服务端应以的协议,方法返回协议对应的通信实现。
### 实例 ### 实例
@ -25,6 +26,9 @@
public string HellowWorld(string name); public string HellowWorld(string name);
} }
/// <summary>
/// Web服务协议实现
/// </summary>
public class WebSvc:IWebSvc public class WebSvc:IWebSvc
{ {
public string HellowWorld(string name) { public string HellowWorld(string name) {
@ -32,6 +36,8 @@
} }
} }
//Program.cs
using Falcon.SugarApi.WebService; using Falcon.SugarApi.WebService;
using Server; using Server;
@ -50,16 +56,24 @@
~~~c# ~~~c#
using System.ServiceModel; using System.ServiceModel;
[ServiceContractAttribute(ConfigurationName = "Service.IWebSvc")]
/// <summary>
/// Web服务协议,与服务端匹配
/// </summary>
[ServiceContract]
internal interface IWebSvc internal interface IWebSvc
{ {
[OperationContractAttribute(Action = "http://tempuri.org/IWebSvc/HellowWorld",ReplyAction = "http://tempuri.org/IWebSvc/HellowWorldResponse")] [OperationContract]
Task<string> HellowWorldAsync(string name); Task<string> HellowWorldAsync(string name);
} }
//Program.cs
using Falcon.SugarApi.WebService; using Falcon.SugarApi.WebService;
var svc = WebServiceClient.CreateWebServiceClient<IWebSvc>("http://localhost:5000/WebService.asmx"); var url="http://localhost:5000/WebService.asmx";
var svc = WebServiceClient.CreateWebServiceClient<IWebSvc>(url);
var result=await svc.HellowWorldAsync("Jeck"); var result=await svc.HellowWorldAsync("Jeck");
~~~ ~~~