WCF Client Proxy State
How do I test the state of my proxy before making calls to my WCF service.
I have a duplex channel created using a duplex channel factory.
Before making any calls to the server I want to check 开发者_如何学JAVAthe state of the proxy object created from the channel factory.
I saw this in a book... (to be used in immediate window)
? ((ICommunicationObject)flsProxy).State
But it gave this exception...
Cannot obtain fields or call methods on the instance of type 'System.ServiceModel.ICommunicationObject' because it is a proxy to a remote object.
Is it better to just catch exceptions?
If you create your client proxy using a DuplexChannelFactory<T>
, you should get back a regular old WCF channel:
Callbacks myCallbacks = new Callbacks();
DuplexChannelFactory<IMyService> factory =
new DuplexChannelFactory<IMyService>(myCallbacks,
new NetTcpBinding(), new EndpointAddress(.....));
IMyService proxy = factory.CreateChannel();
and you should be able to cast that to a ICommunicationObject
and check its state:
ICommunicationObject comobj = (ICommunicationObject)proy;
if(comobj.State != CommunicationState.Faulted)
{
// call the service method
}
Where in this chain of statements does it no longer work for you??
精彩评论