Okey我已经尝试了大约一个星期了,而且无法让它工作......
我有一个错误,上面写着:“索引超出了数组的范围” 基本上我所做的是实现wcf,sql数据库的连接字符串工作正常,但在尝试尝试填充数据或尝试访问数据库中的数据时出错。这就是我所做的:
appcofig:
<basicHttpBinding>
<binding name="BasicHttpBinding_ICoreService" 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="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<client>
<endpoint address="http://localhost:4335/PortalService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICoreService"
contract="WcfPortalReference.ICoreService" name="BasicHttpBinding_ICoreService" />
<behaviors>
<endpointBehaviors>
<behavior name="portalBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
webconfig:
<basicHttpBinding>
<binding name="basicHttp" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483646" maxArrayLength="2147483646"/>
</binding>
<services>
<service name="TTM.FRX.WcfPortal.PortalService" behaviorConfiguration="portalBehaviour">
<endpoint address="" bindingConfiguration="basicHttp" binding="basicHttpBinding" contract="TTM.FRX.WcfPortal.Contract.ICoreService" />
<serviceBehaviors>
<behavior name="portalBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
这是我收到错误的地方:
TTMSystem.WcfPortalReference.CoreServiceClient cli = new TTMSystem.WcfPortalReference.CoreServiceClient();
//pass custom credentials
cli.ClientCredentials.UserName.UserName = typeof(AssemblyIdentifierAttribute).ToString().Split(new char[] { '.' })[typeof(AssemblyIdentifierAttribute).ToString().Split(new char[] { '.' }).Length - 1];
cli.ClientCredentials.UserName.Password = ((AssemblyIdentifierAttribute)System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyIdentifierAttribute), false)[0]).Identifier;
return cli;
它到达clientCredentials时会出错(步骤超过用户名,但不是密码 - 用户名未通过) 有人可以帮帮我吗?这是我第一次做这个,我尝试过搜索,但是找不到它......非常感谢!我需要更多信息,请说...
答案 0 :(得分:0)
错误是您正在访问不存在的数组中的元素。
您的代码有:
Length -1
在其中一行的末尾。
如果长度为0,您将尝试访问数组的元素-1,这将导致您获得的错误。