sql - WCF 服务中断对数据库的调用

标签 sql wcf wcf-data-services

我想我应该去点表格:

  • 我有一个用于在服务器端进行数据库调用的服务

  • 使用 IIS

  • 数据库管理系统 = SQL Server 2008 R2

  • 我的连接字符串没有问题,我有正确的凭据

  • 我随机连接到数据库执行此操作(这有效......类连接在这里):

      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 名称有效,但找不到请求类型错误。

我的应用程序 -> WCF 服务 -> 连接到数据库 -> 运行查询 -> 返回值

最佳答案

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

behaviorConfiguration="模拟行为"

否则,这是行不通的。 Silverlight 应用程序或控制台应用程序不需要这样做

关于sql - WCF 服务中断对数据库的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11346854/

相关文章:

mysql - POSTGRESQL:满足 2 个条件时对字段求和

sql - System.ServiceModel.FaultException SQL错误,是他们结束了吗?

c# - http工作时如何测试WCF net.tcp?

C# - 设计问题建议 : Can't Use Dictionary then what?

mysql - 在mysql中的单个查询中更新两个表

sql - 尝试插入 SQL Azure 数据库表记录时出错

c# - 从对 HttpWebRequest 的调用中复制 HTTP 请求/响应 header ?

c# - WCF 数据服务部署问题 AZURE

wcf - 如何为新的Silverlight应用程序在WCF,REST,POX和RIA服务之间进行选择

c# - SQLDataReader 运行速度太慢取决于标准