c# - 使用 WCF 端点时出现 400 错误请求响应
问题描述
尝试使用 HttpClient 向本地 iis 托管的 WCF 服务的端点发出请求时,我收到 400 Bad Request 响应。该调用在 .NET Core 微服务中实现,如下所示:
private static readonly HttpClient client = new HttpClient();
public async Task<ActionResponse> SomeAction(ActionRequest request, ShoppingCart shoppingCart) {
//non-related code
var requestObject = new WcfServiceRequest() {
OrderData = shoppingCart.Order,
VoucherCode = request.VoucherCode,
Check = request.Check,
Identifier = shoppingCart.Order.Identifier,
DontGenerateNewOrdernumber = true
};
var requestContent = JsonConvert.SerializeObject(requestObject, settings);
HttpResponseMessage serviceResponse = await client.PostAsync(new Uri("http://localhost/SomeApplicationServicePortal/Services/WcfPortalService.svc/web/SomeEndpoint"),
new StringContent(requestContent, Encoding.UTF8, "application/json"));
//more non-related code
}
另一方面,合同如下:
[DataContract]
public class WcfServiceRequest {
[DataMember]
public string Identifier { get; set; }
[DataMember]
public Order OrderData { get; set; }
[DataMember]
public Client ClientData { get; set; }
[DataMember]
public string VoucherCode { get; set; }
[DataMember]
public bool Check;
[DataMember]
public bool ExistingOrder;
[DataMember]
public bool DontGenerateNewOrdernumber { get; set; }
}
此刻我不知道该怎么做。如果有人帮助我解决这个问题,我将非常感激。
编辑:
其 web.config 文件中包含的 WCF serviceModel 如下:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webHttpEndpointBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
<binding name="webHttpEndpointBindingSsl" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Transport" />
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ApplicationManager.ServicePortal.Services.WcfPortalServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ApplicationManager.ServicePortal.Services.WcfPortalServiceBehavior" name="ApplicationManager.ServicePortal.Services.WcfPortalService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicBinding" contract="ApplicationManager.ServiceContracts.IApplicationManagerServicePortal">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="web" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webHttpEndpointBinding" contract="ApplicationManager.ServiceContracts.IApplicationManagerServicePortal" />
<endpoint address="web" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webHttpEndpointBindingSsl" contract="ApplicationManager.ServiceContracts.IApplicationManagerServicePortal" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /></system.serviceModel>
解决方案
推荐阅读
- excel - 在 MS Excel 工作表中并排分离两个表格
- vue.js - 在vue js md-table中隐藏列标题
- django - django rest框架中嵌套序列化程序中的反向关系
- openshift - Openshift:使用最新提交重新部署 source-to-image 容器
- laravel - laravel 刀片 @include 与本地化变量
- rust - rust 在 x86_64 机器上编译 x86 库
- c# - 在 WPF 的行单元格中使用按钮和组合框
- c# - 无法将字符串转换为 XElement
- vim - Vim:保存和退出时替换字符串
- c# - Azure 通知中心管理 SDK - 缺少指标?