WCF 客户端在调用服务时挂起

问题描述 投票:0回答:3

我有一个使用这些设置公开的 C# WCF 服务(出于隐私问题更改了一些数据):

<system.serviceModel>
<services>
  <service name="TrackingService">
    <host>
      <baseAddresses>
        <add baseAddress="http://201.223.147.32:9245/TrackingService"/>
      </baseAddresses>
    </host>
    <endpoint address="" binding="basicHttpBinding" contract="ITrackingService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

<bindings>
  <basicHttpBinding>
    <binding name ="SecuredBasic">
      <security mode = "Message"/>
    </binding>
  </basicHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

我正在使用以下合约:

[ServiceContract, XmlSerializerFormat]
public interface ITrackingService
{
    [OperationContract]
    EquipmentInfo[] GetEqpCollection(string login, string password);
}

当然,EquipmentInfo结构是用[DataContract]属性修饰的。

当我从 WCF 客户端调用此方法时,客户端只是挂在上面的最后一行:

var wcfConn = new TrackingService();
EquipmentInfo[] eqpArray = wcfConn.GetEqpCollection("tr", "service");

我很确定这项服务有效,因为其他方法有效。唯一不起作用的 2 个方法是返回值的方法。为什么客户端在调用服务时会卡住?

ITrackingService的实现:

public EquipmentInfo[] GetEqpCollection(string login, string password)
{
    var eqpList = new List<EquipmentInfo>();
    var eqpCol = EqpDataCollection.Instance.GetCopy();
    
    foreach (DataRow eqp in eqpCol.Rows)
    {
        var rowEqp = new EquipmentInfo();
        rowEqp.HostID = (string)eqp["HostID"];
        eqpList.Add(rowEqp);
    }
    return eqpList.ToArray();
}

编辑2:

public DataTable GetCopy()
{
    lock (_objSync)
    {
        return Copy();
    }
 }
c# wcf
3个回答
2
投票

通过在服务器上启用跟踪来检查日志。


2
投票

EquipmentInfo[]
有多大?有可能响应对于 WCF 的默认设置来说太大,这导致服务器无法序列化和发送消息。在这种情况下,客户端将挂起并等待响应,直到达到超时为止。

尝试使用 maxBufferPoolSize、maxBufferSize 和 maxReceivedMessageSize 属性增加元素中的消息大小。详情在这里:http://msdn.microsoft.com/en-us/library/ms731361.aspx


1
投票

我会说只要 GetEqpCollection() 服务调用没有返回,客户端就会等待/冻结。

我会先检查两件事,如果你只是返回一个空列表会发生什么。只是为了在客户服务沟通工作中看到。

public EquipmentInfo[] GetEqpCollection(string login, string password)
{
   return new List<EquipmentInfo>();
}

其次,我会使用测试项目在服务器端检查您的 GetEqpCollection()。只是为了确保它有效。

© www.soinside.com 2019 - 2024. All rights reserved.