Search code examples
wcfbindingconnectionportal

Index was outside the bounds of the array (please help)


Okey I've tried searhing this for about a week now and just can't get it to work...

I've got an error that reads: "Index was outside the bounds of the array" Basically what I've done is implement wcf, the connection string to the sql database works fine, but I get an error when trying to attemp to populate data or trying to reach data in the database. This is what I've done:

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

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

This is where I get the error:

    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;

It gives the error when it gets to clientCredentials (Steps over username, but not password - username doesn't come through) Can anybody please help me with this? This is my first time working on this and I've tried searching, but just can't find it... Thanks so much in advance!!! I you need more information please just say...


Solution

  • The error is that you are accessing an element in an array that does not exist.

    Your code has:

    Length -1 
    

    at the end of one of the lines.

    If the length is 0 you will try to access element -1 of the array, which would give the error that you are getting.