简体   繁体   中英

WCF Client hangs when calling Service

I have a C# WCF Service exposed with these settings (changed some data for privacy issues):

<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>

I'm using the following contract:

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

Of course, the EquipmentInfo struct is decorated with [DataContract] attribute.

When I call this method from a WCF Client, the client just hangs in the last line above:

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

I'm pretty sure this service is working because other methods are working. The only 2 methods that does not work are the ones that return values. Can you help me understand why client freezes when calling the service?

Thank you!

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

EDIT2:

public DataTable GetCopy()
{
    lock (_objSync)
    {
        return Copy();
    }
 }

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

How big is the EquipmentInfo[] ? It's possible that the repsonse is too big for WCF's default settings, which causes the server to fail to serialize and send the message. The client, in this case, is left hanging and waiting for a response until the timeout is reached.

Try increasing the message size in the element, using the maxBufferPoolSize, maxBufferSize and maxReceivedMessageSize attributes. Details are here: http://msdn.microsoft.com/en-us/library/ms731361.aspx

i would say the client wait/freeeze as long as there is no return from the GetEqpCollection() service call.

i would check 2 things first, what happen if you simply return a empty list. Just to see in client service communication works.

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

and second i would check the your GetEqpCollection() on server side with a test project. just to be sure it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM