0

好吧,我已经尝试搜索这个大约一个星期了,但无法让它工作......

我有一个错误,上面写着:“索引超出了数组的范围”基本上我所做的是实现 wcf,到 sql 数据库的连接字符串工作正常,但是在尝试填充时出现错误数据或试图访问数据库中的数据。这就是我所做的:

应用配置:

    <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>

网络配置:

    <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 时它会给出错误(步骤超过用户名,但不是密码 - 用户名没有通过)有人可以帮我解决这个问题吗?这是我第一次在这方面工作,我已经尝试过搜索,但就是找不到...提前非常感谢!!!我需要更多信息,请说...

4

1 回答 1

0

错误是您正在访问不存在的数组中的元素。

您的代码有:

Length -1 

在其中一行的末尾。

如果长度为 0,您将尝试访问数组的元素 -1,这将给出您得到的错误。

于 2013-02-06T17:14:36.093 回答