我正在使用WCF(C#)构建API并使用Postman对其进行测试.我似乎在使用Postman中的"Params"部分时遇到了麻烦,因为它正在将我输入的任何键值对转换为Query String Params.
我的合同如此规定了UriTemplate ......
[OperationContract]
[WebGet(UriTemplate = "/GetClientDataFromAlias/Alias/{alias}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
GetClientDataFromAliasResponse GetClientDataFromAlias(string alias);
Run Code Online (Sandbox Code Playgroud)
然而,当我通过Postman运行请求时,URL被翻译成以下内容......
http://troikawcf.localhost/ClientWCFService.svc/GetClientDataFromAlias?Alias=myalias
Run Code Online (Sandbox Code Playgroud)
我希望它翻译成以下内容,以符合我的合同
http://troikawcf.localhost/ClientWCFService.svc/GetClientDataFromAlias/Alias/myalias
Run Code Online (Sandbox Code Playgroud)
我错过了Postman中的设置来设置Path格式的所有参数吗?或者我是否需要更改合同以使用查询字符串参数?
请参阅下面的屏幕抓取以获取更多信
非常感谢
我正在使用 RestSharp 与 .Net Core Web API 进行通信。客户端和服务器都是我写的。
我有一套服务,全部继承一个基类,其中包含一个通过 RestClient 执行请求的异步方法。这是基类中创建 RestClient 的方法。
private async Task<ServiceResponse> RequestAsync(ServiceRequest request)
{
try
{
var result = await new RestClient(_digiCore.Config.GetApiBaseUrl()).ExecuteTaskAsync(request.Request, request.CancellationTokenSource.Token);
switch (result.StatusCode)
{
case HttpStatusCode.OK:
case HttpStatusCode.Created:
case HttpStatusCode.NoContent:
return new ServiceResponse
{
Code = ServiceResponseCode.Success,
Content = result.Content
};
// User wasn't authenticated for this one - better luck next time!
case HttpStatusCode.Unauthorized:
Logger.LogError($"Unauthorized {request.Method.ToString()}/{request.Path}");
default:
Logger.LogError($"An error occurred {request.Method.ToString()}/{request.Path}");
}
}
catch (Exception e)
{
Logger.LogError($"A Rest Client error occurred …Run Code Online (Sandbox Code Playgroud) 我定义了一个自定义IViewLocationExpander来检查多租户 Web 应用程序中特定于站点的视图。
想象一下有两个租户 WebsiteA 和 WebsiteB 以及HomeController和Index View的以下文件结构
我的 IViewLocationExpander 将为 WebsiteA 呈现Views/Home/WebSiteA/Index.cshtml ,为 WebsiteB 呈现Views/Home/Index.cshtml - 因为没有特定于 WebsiteB 的索引视图,因此它使用默认视图。
我还在视图中设置了一个名为“Common”的文件夹来保存任何部分视图 - 这个想法是我可以以相同的方式呈现自定义部分视图(例如标题)。
这是我的IViewLocationExpander的代码
public sealed class TenantViewLocationExpander : IViewLocationExpander
{
private ITenantService _tenantService;
private string _tenant;
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
string[] locations =
{
"/Views/{1}/" + _tenant + "/{0}.cshtml",
"/Views/Common/" + _tenant + "/{0}.cshtml",
"/Views/Shared/" + _tenant …Run Code Online (Sandbox Code Playgroud)