我的app.config工作吗?截断的数据

时间:2014-03-28 12:23:56

标签: c# .net web-services wcf config

这是我第一个编写客户端和服务器端的WCF服务项目。我来自Windows窗体背景。 我想我一直遇到数据包/接收缓冲区大小的问题,但我不知道如何测试我的app.config是否正常工作或我做错了什么。

客户端项目的app.config设置如下,它的testproj.exe.config正确反映了内容

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IPulseWebService"
                 closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8"
            useDefaultWebProxy="true">
          <readerQuotas
    maxArrayLength="2147483647"
    maxBytesPerRead="2147483647"
    maxDepth="2147483647"
    maxNameTableCharCount="2147483647"
    maxStringContentLength="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="blah"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPulseWebService"
            contract="ServiceReference1.IPulseWebService" name="WSHttpBinding_IPulseWebService">
            <identity>
                <dns value="localhst" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

我的网络服务的webservice.dll.config包含以下service.serviceModel部分

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IPulseWebService"
                 closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8"
            useDefaultWebProxy="true">
          <readerQuotas
         maxArrayLength="2147483647"
         maxBytesPerRead="2147483647"
         maxDepth="2147483647"
         maxNameTableCharCount="2147483647"
         maxStringContentLength="2147483647" /> 
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IPulseWebService" 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="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>  
    </bindings>

  <services>
    <service name="SmartcentreWcfLib.PulseWebService">
      <host>
        <baseAddresses>
          <add baseAddress="http://l0calhost:8732/Design_Time_Addresses/SmartcentreWcfLib/PulseWebService/" />
        </baseAddresses>
      </host>
      <!-- Service Endpoints -->
      <!-- Unless fully qualified, address is relative to base address supplied above -->
      <endpoint  address="" binding="wsHttpBinding"
                 bindingConfiguration="WSHttpBinding_IPulseWebService"
                 contract="SmartcentreWcfLib.IPulseWebService">
        <!-- 
            Upon deployment, the following identity element should be removed or replaced to reflect the 
            identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
            automatically.
        -->
        <identity>
          <dns value="l0calhost" />
        </identity>

      </endpoint>
      <!-- Metadata Endpoints -->
      <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
      <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, 
        set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="True" />
        <!-- To receive exception details in faults for debugging purposes, 
        set the value below to true.  Set to false before deployment 
        to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

在我的服务器端wcf dll中,我有以下函数作为返回某些数据行的测试。每行是存储在字典中的一组键/值对。每个对象应该是一个简单的byte []或变量类型。

  List<IDictionary<string, object>> IAuditV1.ReadAuditForStaffMember(long staffId, DateTime startDate, 
    DateTime endDate, Int32 recordCount)
  {
      List<TableAdminAudit> tempResult = DatabaseInterface.Instance.AuditQueries.ReadAdminAudit(staffId, startDate,
        endDate, recordCount);
      return tempResult.Select(record => record.PrepareForWebInterface()).Cast<IDictionary<string, object>>().ToList();
  }// function

在我的客户端应用程序中,我正在运行以下循环,这只会增加接收记录的数量。

      Int32 totalRecords = 0;
      while (true)
      {
        results = client.ReadAuditForStaffMember(1, DateTime.MinValue, DateTime.Now, totalRecords);
        totalRecords += 10; //results.Length;
        if (totalRecords == 0) break;
      }

在第3个循环中,当返回的缓冲区大小达到30个记录时,我收到以下错误消息。 我查找了错误,论坛建议它与收到整个数据之前的连接关闭有关,所以更改各种缓冲区大小等。从我的配置文件中可以看出,我已经提升了我所知道的所有值到2147483647,但它没有用。 所以我不知道从哪里开始。有人可以帮忙吗?

System.ServiceModel.CommunicationException occurred
  HResult=-2146233087
  Message=An error occurred while receiving the HTTP response to blah2/Design_Time_Addresses/SmartcentreWcfLib/PulseWebService/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at WcfTester.ServiceReference1.IPulseWebService.ReadAuditForStaffMember(Int64 staffId, DateTime startDate, DateTime endDate, Int32 startIndex)
       at WcfTester.ServiceReference1.PulseWebServiceClient.ReadAuditForStaffMember(Int64 staffId, DateTime startDate, DateTime endDate, Int32 startIndex) in W:\Projects\pulse.smartcentre.root\pulse.smartcentre\WcfTester\Service References\ServiceReference1\Reference.cs:line 481
       at WcfTester.Program.Main(String[] args) in W:\Projects\pulse.smartcentre.root\pulse.smartcentre\WcfTester\Program.cs:line 40
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The underlying connection was closed: An unexpected error occurred on a receive.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       InnerException: System.IO.IOException
            HResult=-2146232800
            Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
            Source=System
            StackTrace:
                 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                 at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                 at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
            InnerException: System.Net.Sockets.SocketException
                 HResult=-2147467259
                 Message=An existing connection was forcibly closed by the remote host
                 Source=System
                 ErrorCode=10054
                 NativeErrorCode=10054
                 StackTrace:
                      at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                      at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                 InnerException:** 

1 个答案:

答案 0 :(得分:0)

文件something.dll.config 从不使用。您需要将这些设置复制到web.config或servicehost.exe.config文件中。

这是.NET自第1天以来的工作方式,并非特定于WCF。考虑到多个&#34;可执行文件&#34;可以使用给定的DLL,并且每个DLL可能具有不同的DLL设置。