WCF服务分解对数据库的调用

时间:2012-07-05 14:50:38

标签: sql wcf wcf-data-services

我想我应该去指点:

  • 我有一个服务,用于在服务器端进行数据库调用
  • 使用IIS
  • DBMS = SQL Server 2008 R2
  • 我的connectionstring不是问题,我有正确的凭据
  • 我随机连接到数据库这样做(这可以...这个类在这里连接):

    using (Database db = base.SystemDatabase())
    
  • 上面的一行并不总是如此。

  • 如果我最终连接,它会在我设置SqlCommand时中断。

以下是我的WCF服务的配置:

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

我会试着看看我是否能收到确切的错误信息......

修改

嘿伙计们,感谢您的投入。我一直在打破这个问题,当我进行一个wcf调用然后进行远程调用然后给我一个

时,这似乎是一个问题。
{"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 

编辑2

在我继续调查此问题后,问题不在于WCF。在运行时,WCF服务正在以它应该的方式工作。实际问题是WCF服务正在尝试调用数据库,但是当我尝试连接时,我得到一个DNS名称有效,但找不到请求类型错误。

我的应用 - &gt; WCF服务 - &gt;连接到数据库 - &gt;运行查询 - &gt;返回值

1 个答案:

答案 0 :(得分:2)

在app.config文件中,我们必须在端点中显式设置behaviorConfiguration。例如:

behaviorConfiguration = “ImpersonationBehaviour”

否则,这将无效。这对于Silverlight应用程序或控制台应用程序不是必需的