簡體   English   中英

WCF客戶端在調用服務時掛起

[英]WCF Client hangs when calling Service

我有一個暴露於這些設置的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");

我很確定這項服務可以正常工作,因為其他方法也可以正常工作。 僅有的兩種不起作用的方法是返回值的方法。 您能幫我理解為什么客戶在致電服務時凍結了嗎?

謝謝!

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();
    }
 }

通過在服務器上啟用跟蹤來檢查日志。

EquipmentInfo[]有多大? 對於WCF的默認設置,響應可能太大,從而導致服務器無法序列化和發送消息。 在這種情況下,客戶端將保持掛起狀態並等待響應,直到達到超時為止。

嘗試使用maxBufferPoolSize,maxBufferSize和maxReceivedMessageSize屬性增加元素中的消息大小。 詳細信息在這里: http : //msdn.microsoft.com/zh-cn/library/ms731361.aspx

我會說,只要GetEqpCollection()服務調用沒有返回,客戶端就會等待/凍結。

我會先檢查2件事,如果您只返回一個空列表會發生什么。 只是為了在客戶服務溝通中看到有效。

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

第二,我將在服務器端通過測試項目檢查您的GetEqpCollection()。 只是為了確保它能正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM