问题描述
我正在使用绰号字符串从excel VBA代码调用WCF服务.但是,由于我的服务返回大量数据作为响应,因此excel会给出错误消息
I am calling my WCF service from excel VBA code using moniker string. However, as my service returns large data as response, excel gives error message
超出了传入消息的最大消息大小配额(65534).要增加配额,请在适当的绑定元素上使用MaxReceivedMessageSize属性"
"Maximum message size quota for incoming messages (65534) has been exceeded. To increase the quota used the MaxReceivedMessageSize property on the appropriate binding element"
这是绰号字符串:
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文件中增加了大小,如下所示:
To resolve this, I increased the size in my WCF service's web.config file as shown below:
<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代码来做到这一点?
According to various forums on this topic, the above solution should work. But this does not work in my case when called from excel. Is there anything I need to do from excel side to set the maxReceivedMessageSize? If yes then how can I do this using VBA code?
其他信息:
我使用Office 2010(带有VBA),Windows 7 Prof,64位OS
I use Office 2010 (with VBA), Windows 7 Prof, 64bit OS
推荐答案
您应该设置maxReceivedMessageSize ="2147483647"以增加消息的大小.
You should set maxReceivedMessageSize="2147483647" to increase message size.
尝试增加消息大小,例如:
Try increasing message size like:
<binding maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
-或
<basicHttpBinding>
<binding name="BasicHttpBinding_IManagementService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
请参考
更新
您还可以通过编程方式更改端点/服务行为.
You also can change endpoint/service behavior programatically.
引用链接:
Update2:
对不起,尼尔,以前我完全忽略了您在excel中执行的操作.
Sorry Anil, Previously I totally overlook you are doing this in excel.
您的方案使用VB6中的WCF服务的最简单方法是为服务客户端创建.Net ComObject包装器.然后在VB6中,您要做的只是创建对象并在该对象上调用一些方法.所有WCF工作都在.Net com对象中进行.
The easiest way for your scenario to use WCF service from VB6 is to create a .Net ComObject wrapper for the service client. Then in VB6 all your are doing is a create object and calling some methods on the object. All the WCF work takes place in the .Net com object.
按照本 链接 .将.NET程序集注册为类型库,然后将其从VB6应用程序链接: 链接 .
Simply create the WCF client to the service in a separate project as described in this link. Register the .NET assembly as a type library which you would then link from the VB6 app : link.
来源:
希望它会有所帮助.:)
Hope it helps. :)
这篇关于从Excel调用WCF服务会在收到的邮件大小上产生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!