我正在使用名字对象字符串从 excel VBA 代码调用我的 WCF 服务。但是,当我的服务返回大数据作为响应时,excel 会给出错误消息
“已超出传入消息 (65534) 的最大消息大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性”
这是名字对象字符串:
addrToService = "service4:mexAddress=""net.tcp://localhost/MyApp/API/Excel/ExcelAPIService.svc/mexTCP"", "
addrToService = addrToService + "address=""net.tcp://localhost/PruCapWebCMHost/API/Excel/ExcelAPIService.svc"", "
addrToService = addrToService + "contract=""IExcelAPIService"", contractNamespace=""http://Prucap/Services"", "
addrToService = addrToService + "binding=""NetTcpBinding_IExcelAPIService"", bindingNamespace=""http://MyApp/Services"""
为了解决这个问题,我增加了 WCF 服务的 web.config 文件的大小,如下所示:
<netTcpBinding>
<binding name="NetTcpBinding_IPublicService" maxBufferPoolSize="8388608" maxBufferSize="8388608" maxReceivedMessageSize="8388608" portSharingEnabled="true">
</binding>
</netTcpBinding>
<basicHttpBinding>
<binding name="BasicHttpBidning_IPublicService" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:05:00" receiveTimeout="00:05:00" maxReceivedMessageSize="8388608" />
<binding name="BasicHttpBidning_ISecureService" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:05:00" receiveTimeout="00:05:00" maxReceivedMessageSize="8388608" />
</basicHttpBinding>
....
<service name="ExcelAPIService" behaviorConfiguration="PublicServiceTypeBehaviors">
<endpoint address="" bindingNamespace="http://MyApp/Services" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IPublicService" contract="API.Service.ExcelAPI.IExcelAPIService" name="NetTcpBinding_IExcelAPIService" />
<endpoint address="" bindingNamespace="http://MyApp/Services" binding="basicHttpBinding" bindingConfiguration="BasicHttpBidning_IPublicService" contract="API.Service.ExcelAPI.IExcelAPIService" name="BasicHttpBidning_IExcelAPIService" />
<endpoint address="mex" bindingNamespace="http://MyApp/Services" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mexTCP" bindingNamespace="http://MyApp/Services" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>
根据有关此主题的各种论坛,上述解决方案应该有效。但这在我的情况下从 excel 调用时不起作用。我需要从 excel 端做些什么来设置 maxReceivedMessageSize 吗?如果是,那么我该如何使用 VBA 代码来做到这一点?
附加信息:
我使用 Office 2010(带 VBA)、Windows 7 Prof、64 位操作系统