我正在构建一个 InfoPath 表单(InfoPath 2010),并且在自定义代码中我以编程方式调用 WCF 服务作为提交操作的一部分,如下所示:
DriverHours.DriverHours allHours = new DriverHours.DriverHours(); 布尔规格;
XPathNavigator myNav = this.MainDataSource.CreateNavigator();
string allData = myNav.OuterXml;
allData = allData.Replace("my:", "");
result = allHours.SaveDriverHoursByString(allData);
SaveDriverHoursByString 只接受一串 XML 数据,通过 WCF 将其保存到后端的数据库中。
当提交块执行时,最后一行显示以下错误:
System.Web.Services.Protocols.SoapHeaderException
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:Xml. The InnerException message was 'There was an error deserializing the object of type System.String. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 208, position 21.'. Please see InnerException for more details.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at HrsServicetemplate.DriverHours.DriverHours.SaveDriverHoursByString(String Xml)
at HrsServicetemplate.FormCode.FormEvents_Submit(Object sender, SubmitEventArgs e)
at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnSubmit(DocReturnEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnSubmitRequest(DocReturnEvent pEvent)
现在我知道解决方案是增加 WCF 服务的 web.config 上的内容长度。下面是我现在的 web.config 文件,但仍然出现错误:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!--<add name="IFMS_Connection" connectionString="Data Source=aaaa;User Id=aaaa;Password=abcdefg;"/> -->
<add name="IFMS_Connection" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=aaaa)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME = ORCLDEVL)));User Id=aaa;Password=aaaa;"/>
</connectionStrings>
<system.web>
<httpRuntime maxRequestLength="2147483647" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NoSecurityBinding" maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"/>
<message establishSecurityContext="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="metadataAndDebug">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug
includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
有任何想法吗?特别是我想知道缺少配置条目,谢谢!