469,299 Members | 2,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Exception handling in NetTcpBinding vs BasicHttpBinding

I hosted my WCF service in a Console App. the service is tagged to run as a
singleton , [ServiceBehavior(InstanceContextMode=InstanceContex tMode.Single)]

The service implements following two methods
One that throws exception
public void ThrowException()
{
throw new Exception("Exception thrown");
}

public string GetString()
{
return "Hello";
}

In the client code I do the following:

MyService service = new MyService();
try
{
service.ThrowException();
}
catch(Exception e)
{
}

service.GetString();

When I use basicHttpBinding, the first call throws exception as
expected...and the second call successfully returns the right string.

But when I use netTcpBinding, after the first call throws an exception, when
I try to call the second method, WCF throws an exception

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

Why is the behavior different between these two bindings?

-------------------------basicHttp------------------
Service side config

<services>
<service name="MyService">
<endpoint address="http://www.foo.com/mysvc"
binding="basicHttpBinding" name="MySvc" contract="Company.IMyService" />
</service>
</services>
Client side config
<client>
<endpoint address="http://www.foo.com/mysvc"
binding="basicHttpBinding" contract="IMyService" name="MySvc" />
</client>
-------------------------------------------

-------------------------netTcpBinding------------------
Service side config

<services>
<service name="MyService">
<endpoint address="net.tcp://www.foo.com/mysvc"
binding="netTcpBinding" bindingConfiguration="MyBinding" name="MySvc"
contract="Company.IMyService" />
</service>
<bindings>
<netTcpBinding>
<binding name ="MyBinding">
<security mode="None"></security>
<reliableSession enabled ="True" ordered ="False"/>
</binding>
</netTcpBinding>
</bindings>
</services>
Client side config

<netTcpBinding>
<binding name="MyTcpBinding" receiveTimeout ="00:01:00">
<security mode ="None"></security>
<reliableSession enabled ="True" ordered ="False"/>
</binding>
</netTcpBinding>

<client>
<endpoint address="net.tcp://www.foo.com/mysvc"
binding="netTcoBinding" bindingConfiguration="MyTcpBinding"
contract="IMyService" name="MySvc" />
</client>
-------------------------------------------
Oct 23 '08 #1
0 2397

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by adi | last post: by
3 posts views Thread by Master of C++ | last post: by
2 posts views Thread by tom | last post: by
9 posts views Thread by C# Learner | last post: by
44 posts views Thread by craig | last post: by
41 posts views Thread by Zytan | last post: by
1 post views Thread by George2 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.