底层连接已关闭:连接意外关闭wcf服务

时间:2013-06-20 08:53:50

标签: wcf service-reference

基础连接已关闭:连接意外关闭

这是一般错误,因为我对wcf很新,所以我不知道从哪里开始诊断问题。我一直在谷歌搜索几个小时,真的需要一个有更多wcf经验的人的建议。所以请耐心等待,我会尽力描述问题。 我的域由wcf项目和类库项目组成,其中我有数据实体。我有1个svc文件。我在我的asp.net mvc 3控制器中调用该服务。做一些非常简单的事。我将发布相关代码和堆栈跟踪。

我正在尝试在候选控制器的列表操作中显示候选列表。我在mvc项目中添加了一个服务引用,并将其指向我的localhost(它被发现并正在运行的服务)。

堆栈追踪:

[WebException: The underlying connection was closed: The connection was closed unexpectedly.]
   System.Net.HttpWebRequest.GetResponse() +6117395
   System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48

[CommunicationException: The underlying connection was closed: The connection was closed unexpectedly.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9440287
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   ADMWeb.UI.ADMServices.IADM.GetCandidateList() +0
   ADMWeb.UI.ADMServices.ADMClient.GetCandidateList() in C:\Users\ori\Documents\Visual Studio 2010\Projects\ADMWeb\ADMWeb.UI\Service References\ADMServices\Reference.cs:1025
   ADMWeb.UI.Controllers.CandidatesController.Index() in C:\Users\ori\Documents\Visual Studio 2010\Projects\ADMWeb\ADMWeb.UI\Controllers\CandidatesController.cs:22
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9030045
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

错误:

Line 1024:        public ADMWeb.UI.ADMServices.Candidate[] GetCandidateList() {
Line 1025: return base.Channel.GetCandidateList(); Line 1026:        }

ADM.svc:

namespace ADMServices
{
    public class ADM : IADM
    {
        public List<Candidate> GetCandidateList()
        {
            List<Candidate> candidateList = new List<Candidate>();
            candidateList = CandidateManager.GetCandidateList();

            return candidateList;
        }
    }
}

候选人控制员(列表行动):

ADMClient client = new ADMClient();
List<Candidate> candidates = client.GetCandidateList().ToList();
return View(candidates);

WCF Project web.config:

    <?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <connectionStrings>
    <add name="ADMConnectionString" connectionString="Data Source=;Initial Catalog=ADM_ATID;Persist Security Info=True;User ID;Password"
    providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.serviceModel>
    <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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="Information, ActivityTracing">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="Error.svclog" />
    </sharedListeners>
  </system.diagnostics>
</configuration>

MVC web.config:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IADM" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      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>
<client>
  <endpoint address="http://localhost:49341/ADM.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IADM" contract="ADMServices.IADM"
    name="BasicHttpBinding_IADM" />
</client>

1 个答案:

答案 0 :(得分:2)

我要做的第一件事是,我将返回一个空列表而不是返回候选人的完整列表。如果工作正常,那么很明显数据的大小是个问题。使用绑定参数修改大小播放。