Search code examples
sqlwcfwcf-data-services

WCF Service breaks down call to database


I guess I should go point form:

  • I have a service that I use to make database calls on the server side

  • uses IIS

  • DBMS = SQL Server 2008 R2

  • my connectionstring is not a problem, I have the right credentials

  • I randomly connect to the database doing this (this works... the class connects here):

      using (Database db = base.SystemDatabase())
    
  • The line above does not always make it.

  • If I do end up connecting, it will break when I set up my SqlCommand.

Here is the config for my WCF service:

<customBinding>
   <binding name="CustomBinding_ITestDataService">
      <binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                             maxSessionSize="2048">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
   </binaryMessageEncoding>
   <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                  maxReceivedMessageSize="65536" allowCookies="false" 
                  authenticationScheme="Negotiate" bypassProxyOnLocal="false" 
                  hostNameComparisonMode="StrongWildcard"
                  keepAliveEnabled="true" maxBufferSize="65536" 
                  proxyAuthenticationScheme="Anonymous"
                  realm="" transferMode="Buffered" 
                  unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" />
   </binding>
</customBinding>
<behaviors>
   <endpointBehaviors>
      <behavior name="ImpersonationBehaviour">
         <clientCredentials>
             <windows allowedImpersonationLevel="Impersonation"/>
         </clientCredentials>
      </behavior>
   </endpointBehaviors>
</behaviors>
<client>
   <endpoint name="CustomBinding_ITestDataService"
       address="http://test.net/TestApp/TestDataService.svc"
       binding="customBinding" bindingConfiguration="CustomBinding_ITestDataService"
       contract="TestDataService.ITestDataService" >
       <identity>
           <servicePrincipalName value="host/Test.net" />
       </identity>
   </endpoint>
</client>

I'll try and see if I can get the exact error message...

EDIT

Thanks for the input. I have been breaking down the issue, and it seems to be an issue when I make a wcf call which then makes a remoting call which then gives me a

{"The requested name is valid, but no data of the requested type was found"}
    [System.Net.Sockets.SocketException]: {"The requested name is valid, but no data of the requested type was found"}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    InnerException: null
    Message: "The requested name is valid, but no data of the requested type was found"
    Source: "mscorlib"
    StackTrace: "\r\nServer stack trace: \r\n   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)\r\n   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)\r\n   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()\r\n   at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)\r\n   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)\r\n   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)\r\n   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)\r\n\r\nException rethrown at [0]: \r\n   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n   at System.Runtime.Remoting.
Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n   at 

EDIT 2

After I have continued to investigate the issue, it is not WCF the issue. At run time, the WCF service is working the way it should. The actual problem is the WCF service is trying to make a call to the database, but when I try to connect, I get a DNS name is valid, but the request type could not be found error.

My App -> WCF Service -> Connect To Database -> Run Query -> Return value(s)


Solution

  • In the app.config file, we must explicitly set the behaviorConfiguration in the endpoint. For example:

    behaviorConfiguration="ImpersonationBehaviour"

    otherwise, this won't work. This is not required for a Silverlight application or a Console application