我创建了以下网络服务:
/// <summary>
/// Get all users from CRS that are not included in the emaillist
/// </summary>
/// <param name="emailList">string with emails separated by semicolon</param>
/// <returns></returns>
[HttpPost]
[Route("api/user/getwurusersnotinlist/")]
[SwaggerOperation("UserGetWurUsersNotInList")]
public List<UserDto> GetWurUsersNotInList([FromBody] string emailList)
{
var list = Request.Content.ReadAsStringAsync().Result;
var exclude = (emailList??string.Empty).ToLower().Split(';').ToList();
return WurUsers
.Where(user => string.IsNullOrEmpty(user.Email) && !exclude.Contains(user.Email.ToLower()))
.Select(user => user.Dto())
.ToList();
}
正如您所看到的,我正在尝试使用[FromBody] Swagger属性。在客户端,以下代码用于检索用户数据:
StringBuilder sb = new StringBuilder();
var semi = string.Empty;
foreach (var user in students)
{
sb.Append(semi).Append(user.EMail);
semi = ";";
}
var excludeList = sb.ToString();
var crsUsers = UserServiceClient.UserGetWurUsersNotInList(excludeList);
foreach (UserDto crsUser in crsUsers)
{
...
}
此代码的问题是:
===编辑===
以下是客户端Swagger生成的代码:
// Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
namespace WUR.BBCourseEnrollment.Business
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.Rest;
using Models;
/// <summary>
/// </summary>
public partial interface IWurCrsWeb : IDisposable
{
/// <summary>
/// The base URI of the service.
/// </summary>
Uri BaseUri { get; set; }
/// <summary>
/// Gets or sets json serialization settings.
/// </summary>
JsonSerializerSettings SerializationSettings { get; }
/// <summary>
/// Gets or sets json deserialization settings.
/// </summary>
JsonSerializerSettings DeserializationSettings { get; }
/// <summary>
/// Subscription credentials which uniquely identify client
/// subscription.
/// </summary>
ServiceClientCredentials Credentials { get; }
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<HttpOperationResponse<IList<UserDto>>> UserGetAllWithHttpMessagesAsync(Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <param name='emailList'>
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<HttpOperationResponse<IList<UserDto>>> UserGetWurUsersNotInListWithHttpMessagesAsync(string emailList, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
Task<HttpOperationResponse<IList<ScheduleDto>>> UserGetSchedulesWithBlackboardIdWithHttpMessagesAsync(Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
}
}