1 0 Tag Archives: WCF
post icon

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

In the SOA-oriented programming, one of the major mistakes that you make when use WCF services is create an instance of the Transparent Proxy statements within the using statement, as follows:

using(ServiceReference.ClientType client = new ServiceReference.ClientType(“EndpointAddress”))
  {
  //do stuff

 } // <– this line might throw

The error you get is the following:

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

In general, you obtain this error when the service is in a Fault State, so not accessible, but in most cases when the client proxy wasn’t handled properly disposed, so subsequent calls to the first will find the service in faulted state.

To ensure the right management of client proxy disposing, you have to use the Try Catch statement enriched with Finally, as shown below:

ServiceReference.ClientType client = null;

try
{
	client = new ServiceReference.ClientType("EndpointAddress");
	client.Open();

	//do stuff
}
catch (Exception e)
{
	//do stuff
}
finally
{
	if(client != null)
	{
		if (client.State == CommunicationState.Opened)
			client.Close();
		else if (client.State == CommunicationState.Faulted)
			client.Abort();
	}
}

You can find specific references to the following article sull’MSDN: Avoiding Problems with the Using Statement.

November 30th, 2011 @ 01:14
post icon

WCF SOA Hello World – Windows Communication Foundation Service Oriented Architecture Hello World

Ho avuto il piacere di cominciare a studiare WCF e voglio condividere con voi un’ applicazione SOA Hello World che ho creato per cominciare a studiare.

L’applicazione è disponibile qui: HelloWorldWCF.zip (34,25 kb)

Prerequisiti

– Framework.NET 3.5

– Visual Studio 2008

Seguire i seguenti passaggi per la configurazione della Solution:

  1. Estrarre l’archivio in una cartella a piacere (ad esempio C:\)
  2. Creare su IIS un Web Site che faccia da Host per il Servizio ProductRetriever.svc in modo che il servizio sia raggiungibile al seguente indirizzo: http://localhost/ProductRetriever.svc
  3. Configurare IIS in modo che abbia un nuovo Handler per il tipo *.svc come segue:
    1. Navigare da command fino alla cartella “C:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation”
    2. Eseguire il comando ServiceModelReg -iIl risultato sarà il seguente:

Eseguendo l’applicazione web compresa nella solution si può vedere come consumare il servizio SOA ProductRetriever.svc

Enjoy snippet!

May 4th, 2010 @ 04:25