- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在向网络服务发送请求时,我遇到了一个非常烦人的问题。
请求消息的参数之一是Batch
,可以设置为Y
或N
。当我将其设置为 N
时没有问题,并且我收到包含单个订单详细信息的响应。
但是,当我将 Batch
设置为 Y
时,我看到了这个错误:
Additional information: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
为了解决这个问题,我尝试在调用服务之前设置 MaxReceivedMessageSize
:
public Provider.GetMessageResponse GetOrders(bool acceptBatch)
{
var httpBinding = new BasicHttpBinding();
httpBinding.MaxReceivedMessageSize = 2097152;
httpBinding.MaxBufferSize = 2097152;
var request = BuildRequest(acceptBatch);
var client = new Provider.PullServiceClient();
var response = client.PullGetMessage(SecurityToken, request);
return response;
}
但是,我仍然看到错误消息(尽管我可以看到 httpBinding.MaxReceivedMessageSize
在运行该代码后确实增加了),服务(不是由我托管)告诉我消息已被收集(这确实有道理,因为似乎消息只有在到达我的系统后才会被阻止)。
此外,当我使用 xml 从 SoapUI
应用程序执行完全相同的请求时,我确实收到了一个没有任何问题的批处理响应,并且我可以看到所有可用订单的长列表。
那么这个 MaxReceivedMessageSize
属性是否只适用于我的应用程序而不适用于整个系统?如果是这样,为什么上面的代码不能解决这个问题?
最佳答案
在查看了 Provider.PullServiceClient
的重载构造函数之后,我通过包含以下参数设法解决了这个问题:
var binding = new BasicHttpBinding() { MaxReceivedMessageSize = 2097152, MaxBufferSize = 2097152 };
var endpoint = new EndpointAddress("http://test.providerporal.co.za/testservice/pullservice.svc");
var client = new Provider.PullServiceClient(binding, endpoint);
所以我猜这个限制在某种程度上与我的应用程序有关,但是 HttpBinding
需要绑定(bind)到请求本身。希望这对其他人有帮助。
关于c# - 从应用程序而非 SoapUI 调用批处理服务时出现 MaxReceivedMessageSize 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776875/
我是一名优秀的程序员,十分优秀!