WCF REST 服务 400 错误请求
我有 WCF RESTful 服务和 Android 客户端。
当我发出更大的请求时,服务器会回复 400。看来我有 65k 限制问题 在此处或其他有关同一问题的数百万帖子中。
但是,我似乎无法修复它。这是我的 web.config 的外观
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="myEndpoint" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="1000000" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
这是服务功能的代码示例:
[WebInvoke(UriTemplate = "/trips/{TripId}/inspection", Method = "POST")]
[Description("Used on mobile devices to submit inspections to server")]
public void PostTripInspection(string tripId, Inspection inspection)
{
return;
}
这是我的 Web 项目中托管 WCF (Global.asax.cs) 的代码
private static void RegisterRoutes()
{
// Setup URL's for each customer
using (var cmc = new CoreModelContext())
{
foreach (var account in cmc.Accounts.Where(aa => aa.IsActive).ToList())
{
RouteTable.Routes.Add(
new ServiceRoute(
account.AccountId + "/mobile", new WebServiceHostFactory(), typeof(MobileService)));
}
}
}
根据我的理解,Java HttpClient 不会施加任何限制,因此它位于 WCF 端。有关如何解决此问题或如何在 WCF 中拦截消息的任何指示?
编辑2: 这就是踪迹所显示的。当我修改 standardEndpoint 时它没有帮助...
I have WCF RESTful service and Android client.
Server replies with 400 when I do bigger request. It seems that I have 65k limit issue like
in here or in other million posts on same problem.
However, I can't seem to be able to fix it. Here is how my web.config looks
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="myEndpoint" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="1000000" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
Here is code example of service function:
[WebInvoke(UriTemplate = "/trips/{TripId}/inspection", Method = "POST")]
[Description("Used on mobile devices to submit inspections to server")]
public void PostTripInspection(string tripId, Inspection inspection)
{
return;
}
Here is code inside my Web project which hosts WCF (Global.asax.cs)
private static void RegisterRoutes()
{
// Setup URL's for each customer
using (var cmc = new CoreModelContext())
{
foreach (var account in cmc.Accounts.Where(aa => aa.IsActive).ToList())
{
RouteTable.Routes.Add(
new ServiceRoute(
account.AccountId + "/mobile", new WebServiceHostFactory(), typeof(MobileService)));
}
}
}
From what I understand Java HttpClient doesn't impose any limits so it's on WCF side. Any pointers on how to solve this issue or how to intercept message in WCF?
EDIT 2:
This is what trace shows. And when I modigy standardEndpoint it doesn't help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您看过此链接(类似的 StackOverflow 问题),请原谅我:
Forgive me if you've seen this link (Similar StackOverflow Question):
在这种情况下,您不需要使用流式传输 - 您所需要做的就是增加标准 webHttpEndpoint 上的 maxReceivedMessageSize 配额:
更新:如果配置更改不起作用(我不这样做)知道为什么),你可以尝试在代码中增加它。通过使用自定义服务主机工厂,您可以获得对端点对象的引用,并且可以增加那里的配额。下面的代码显示了一个这样的工厂(您需要更新
RegisterRoute
代码才能使用这个新工厂):You don't need to use streaming in this case - all you need to do is to increase the maxReceivedMessageSize quota on the standard webHttpEndpoint:
Update: if the config change didn't work (I don't know why), you can try increasing it in code. By using a custom service host factory, you get a reference to the endpoint object and you can increase the quota there. The code below shows one such a factory (you'll need to update the
RegisterRoute
code to use this new factory):