2010-05-19 56 views
2

我刚刚创建的WCF服务出现问题。这是昨天工作,但由于某种原因,它只是停止工作。WCF中的CommunicationException

我的一个WCF方法返回一个实体框架实体的阵列,像这样:

public BranchContactDetail[] GetClosestBranches(string postcode, int howManyBranches) 
    { 
     GeoLocation geoLocation = GetLocationFromPostcode(postcode); 
     Location location = new Location(geoLocation.Latitude, geoLocation.Longitude); 

     using (BranchDirectoryEntities entities = new BranchDirectoryEntities()) 
     { 
      var branchesInOrder = entities.BranchContactDetails 
       .Where(b => b.latitude.HasValue && b.longitude.HasValue) 
       .OrderBy(b => location.DistanceFrom(b.latitude, b.longitude)) 
       .Take(howManyBranches) 
       .ToArray(); 

      return branchesInOrder; 
     } 
    } 

...,正如我说的,这是昨天做工精细。现在我得到了“底层连接已关闭:连接意外关闭。”我在网上搜寻了所有东西,但似乎没有人知道答案。任何人都可以在这个问题上发现什么?

问候,马克

回答

0

很可能你有连接问题。我的意思是你无法访问你试图访问的资源。有没有防火墙什么的。 确保尝试从客户机远程登录服务器。

+0

不,我没有返回更多结果。事实上,在测试中,我只会返回更少 - 只有5个实体。 有一点不同的是Branch实体有更多的依赖关系 - 外键等等。可能WCF有这些麻烦吗? – serlingpa 2010-05-20 08:54:13

+0

我没有说它可以连接到结果大小。它可能是连接问题。请阅读上面。 – Incognito 2010-05-20 08:59:18

+0

我已经添加了诊断的东西,因为你建议marc_s,我已经读过正在生产的日志,但我并不聪明。我可以看到异常实际被抛出的位置,但我看不出为什么! !AARGH – serlingpa 2010-05-20 09:06:09

1

与昨天相比,今天你能选择更多的条目吗?难道你的服务方法需要比60秒的默认时间更长的时间来返回数据吗?或者,对于返回的实体,数据大小是否超过64K?

我会做两件事情:

1)打开异常的详细信息,这样就可以在客户端上的详细异常消息 - 应该希望你指出正确的方向

2)打开WCF消息记录看跨线

发生的事情对于点1,您需要启用serviceDebug行为:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="debug"> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="debug" name="YourWCFService"> 

当呼叫失败时,这应该会在客户端提供详细信息。

对于点没有。 2,你需要做以下几个步骤:

里面<system.serviceModel>,你需要添加此诊断标签:

<diagnostics> 
    <messageLogging 
     logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" 
     logEntireMessage="true" logMalformedMessages="true" 
     maxMessagesToLog="2500" maxSizeOfMessageToLog="256000" /> 
</diagnostics> 

,然后你还需要添加到您的app.config或web.config文件:

<system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" 
        switchValue="Information, ActivityTracing" 
        propagateActivity="true"> 
     <listeners> 
      <add name="default" 
       type="System.Diagnostics.XmlWriterTraceListener" 
       initializeData="C:\yourlogfile.svclog" /> 
     </listeners> 
     </source> 
    </sources> 
    <trace autoflush="true" /> 
    </system.diagnostics> 

里有System.Diagnostics命名空间中一对夫妇预定义的跟踪侦听器类型的 - 使用其中任何一种现成的人,或者创建自己的(例如,登录到数据库或此类)。

退房如何启用WCF跟踪这些额外信息来源:

您可以使用WCF Trace Viewer Tool查看这些基于XML的svclog文件 - 非常方便!

相关问题