Skip to Content
avatar image
Former Member

Retrieving Device Count for a Server

I am looking for some sample code which can help me retrieve Total No. of Devices registered on a Server /Farm.

I tried using the Stored Query Example.

public static string serverCapacity_StoredQuery()
            //String contextId = Guid.NewGuid().ToString();
            AfariaStoredQueriesService.StoredQueriesServiceClient svcStoredQueries = null;

                //string apiAddress = "172.18.1.**";
                svcStoredQueries = new AfariaStoredQueriesService.StoredQueriesServiceClient("WSHttpBinding_IStoredQueriesService");
                svcStoredQueries.ClientCredentials.Windows.ClientCredential.Domain = afariaDomain;
                svcStoredQueries.ClientCredentials.Windows.ClientCredential.UserName = afariaUser;
                svcStoredQueries.ClientCredentials.Windows.ClientCredential.Password = afariaPassword;

                AfariaStoredQueriesService.DataState state = new AfariaStoredQueriesService.DataState();
                StoredQueryFilter filter = new StoredQueryFilter();
                filter.QueryId = 1427;
                filter.DoNotAddTenantId = true;
                filter.TenantIdOverride = -1;
                filter.StartRow = -1;
                filter.MaxRows = 5000;

                filter.NameValueLists = new FilterNameValueList[1];
                filter.NameValueLists[0] = new FilterNameValueList();
                filter.NameValueLists[0].VariableName = "nvwh_mkr_filter";
                filter.NameValueLists[0].NameValueListEntries = new FilterNameValueEntry[1];
                filter.NameValueLists[0].NameValueListEntries[0] = new FilterNameValueEntry();
                filter.NameValueLists[0].NameValueListEntries[0].ColumnName = "";
                filter.NameValueLists[0].NameValueListEntries[0].DataType = "string";
                filter.NameValueLists[0].NameValueListEntries[0].DataValue = "%" + "" + "%";
                filter.NameValueLists[0].NameValueListEntries[0].Operator = "like";
                filter.NameValueLists[0].NameValueListEntries[0].Connector = "";

                DataSetSurrogate dss = svcStoredQueries.GetFirstStoredQueryFiltered(filter, out state);

                return (dss.ToString());
                if (svcStoredQueries != null)
                    svcStoredQueries.Close();// Shared, so don't CloseContext()
                    svcStoredQueries = null;


Seems this is not solving my issue. Also I am getting the following error, Please suggest.

  1. System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

Server stack trace:

   at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)

Exception rethrown at [0]:

   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

   at System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)

   at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)

   at System.ServiceModel.ClientBase`1.Close()

   at SAPAfariaProxy.ApiHelper.serverCapacity_StoredQuery() in c:\Sap\Sources - Working Code - 17\SAPAfariaProxy\SAPAfariaProxy\ApiHelper.cs:line 1057

   at SAPAfariaProxy.WebServices.SAPAfariaProxyService.deviceCount() in c:\Sap\Sources - Working Code - 17\SAPAfariaProxy\SAPAfariaProxy\WebServices\SAPAfariaProxyService.asmx.cs:line 95

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 22, 2014 at 05:46 PM

    I haven't reviewed your code yet, but that error is normally a result of buffer problems. It can be many other things, but increasing the buffers in the app.config or through code may help. The Afaria API 101 document covers this some.

    Afaria API 101 - Consuming the Afaria API Services and Creating a Proof of Concept Application

    Add comment
    10|10000 characters needed characters exceeded

    • Looking at this code, it looks like a working example that I've provided previously. I'm not sure what the impact of specifying the ColumnName as an empty string would be, but since you are searching for any results, ClientFriendlyName should be acceptable. If you're still having problems after that, it is probably because of the buffers. This query returns a good bit of data per device, so searching across all tenants would result in a lot of data overall.

      Please let me know if this helps you resolve the question, and mark the question as answered for other's reference if so!