我遇到了一个问题,使用HttpClient和BaseAddress属性调用webHttpBinding WCF端点时出现错误。
HttpClient
我创建了一个HttpClient实例,并将BaseAddress属性指定为本地主机端点。
GetAsync 调用
我接着调用 GetAsync 方法并传入额外的 Uri 信息。
HttpResponseMessage response = await client.GetAsync(string.Format("/Layouts/{0}", machineInformation.LocalMachineName()));
服务终端点
[OperationContract]
[WebGet(UriTemplate = "/Layouts/{machineAssetName}", ResponseFormat = WebMessageFormat.Json)]
List<LayoutsDto> GetLayouts(string machineAssetName);
问题
我遇到的问题是,基地址中的/AndonService.svc
部分被截断了,因此最终的调用指向了https://localhost:44302/Layouts/1100-00277
而不是https://localhost:44302/AndonService.svc/Layouts/1100-00277
,导致404 Not Found错误。
为什么在GetAsync调用中会截断BaseAddress?我该如何解决这个问题?