SecurityMode.None leads to TimeoutException instead of CommunicationObjectFaultedException - wcf

I have a WCF self-hosted service with net.tcp binding.
I need it to be nonsecured with reliable session.
When I configure it to nonsecure all calls to closed service (close, crash, process kill - any reason) lead to timeout exceptions (hang for a minute and timeout). When default (mode = Transport) - I get CommunicationObjectFaultedException at the same moment, seems like infrastructure automatically determines connection break.
How can I get immediate CommunicationObjectFaultedException with nonsecured settings?
Server and client configs are ok. Everything works fine untill I change to nonsecured (of course I change server and client configs).
I've spent many hours to solve the problem, found some similar problems but no answer.
Server config:
<netTcpBinding>
<binding name="TCPBinding" receiveTimeout="Infinite">
<reliableSession enabled="true" inactivityTimeout="00:10:00"/>
<security mode="None">
</security>
</binding>
</netTcpBinding>

Related

Calling wcf service locally taking more time than calling WCF service hosted on IIS on different machine

I am using WCF service at server side hosted on IIS using TCP protocol and winforms client application to call the service.
I am also using Caslte windsor for DI and WCF proxy creation.
var rpt1 = Windsor.Container.Resolve<IReportService>();
var data = rpt1.GetModules();
The problem is when I point my service hosted on IIS on different machine (even on different geographic location), it takes very less time to return the data.
For testing and development purpose, I have created small console based application to host WCF locally.
The problem is now I am facing is when client send request to locally hosted server it takes more than 30 ms to hit debug point in VS at server code base.
This deply is completely random sometimes it takes even more than 4-5 mins.
<bindings>
<customBinding>
<binding name="CustomNetTcpBinding" closeTimeout="01:01:00" openTimeout="01:03:00" receiveTimeout="01:10:00" sendTimeout="01:10:00">
<reliableSession ordered="true" inactivityTimeout="01:10:00" />
<transactionFlow/>
<gZipMessageEncoding enableCompression="true" innerMessageEncoding="textMessageEncoding">
<readerQuotas maxDepth="999999999" maxStringContentLength="999999999" maxArrayLength="999999999" maxBytesPerRead="999999999" maxNameTableCharCount="999999999"/>
</gZipMessageEncoding>
<windowsStreamSecurity/>
<tcpTransport maxReceivedMessageSize="999999999" maxBufferSize="999999999"/>
</binding>
</customBinding>
</bindings>
I also changed maxConnection like below...
<connectionManagement>
<add maxconnection="200" address="*" />
</connectionManagement>
I am using same config during both hosting type(local and IIS).
Can anyone tell me what could be the reason or am I missing something.
Thanks in advance.

Page crahses if repsonse time is more

Im using Silverlight with wcf for my application. When the page requests it goes to the service for the output. But if the response(database operation) takes a bit of time to provide the output then my silverlight page is getting crashed. Can any help me what is the problem.
Sounds like you need to set the timeout settings for the WCF service to be higher to cater for the potential delays. The timeout settings are usually set in the bindings defined in the
<system.serviceModel>
<bindings>
section of the config file.
You will need to make sure that the 'receiveTimeout' in the client config, and the 'sendTimeout' in the service config are set to appropriate values that are high enough to cater for your particular service's timings.
An example 'basicHttpBinding' for the client-side, with a 'receiveTimeout' of 1 minute, 30 seconds could look like this (the important item to note being the 'receiveTimeout'):
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBindingConfig" receiveTimeout="00:1:30">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>

Does setting Security Mode = Transport automatically make it secure in a HTTPS web service?

I have a web service and we're currently hosting it in a HTTPS site.
My binding is this.
<wsHttpBinding>
<binding maxReceivedMessageSize="2000000" >
<readerQuotas maxStringContentLength="2147483647" />
<security mode="Transport">
</security>
</binding>
</wsHttpBinding>
And it seems to work well. But my main aim is to make sure the web service requests and responses are encrypted. I don't know much about web services but is that all there is to it?
Just use HTTPS and put this line in your configuration?
<security mode="Transport">
</security>
Or is there more to it? How can I know if the message's sent are encrypted or not?
Yes that's all. The mode Transport demands transport level security which in your case means HTTPS. If you want to see that messages are encrypted you must use some network monitoring tool (Fiddler, WireShark, etc.)

How could a WCF service become locked?

In my application a Winform UI thread in sync calls a WCF method.
99.99% of the time this is ok, but once in a while the call to the WCF method becomes locked and the UI freezes.
I know I can prevent the freezing of UI by making the call async - most of our WCF calls are async - but we considered it not so bad to make this particular tiny method in sync.
When the lock in the WCF service occurs other users cannot access the service as well. I have to restart the WCF service host (Windows service) to resolve the problem.
How is it possible for a WCF service to become locked and inaccessible?
I can't think of a scenario.
We checked the database, which was running as usual.
Technical details:
We use a proxy in a service agent. This service agent with its proxy is kept alive while the application runs.
[PreserveReferences]
[OperationContract(IsOneWay = false, AsyncPattern = false, Action = "MyMethod")]
MyType MyMethod();
The binding in use:
<wsHttpBinding>
<binding name="AppWsHttpBindingConfig" transactionFlow="true" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="false" enabled="false" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
Most of the WCF service hang problems is related to disposal of WCF client proxies, which i believe is the problem in your case. If you are not disposing client proxies correctly you will get a timeout exception when you make the (maxConcurrentSessions + 1) n-th call.
Please check out this article.
Basically it says that, if your channel is not in a faulted state, calling Abort on that channel frees the client resources but does not free server resources. For example when a service method throws a FaultException it does not put the channel in a faulted state. So calling abort on this proxy will result in an open session in your server with no client.
Wheter this is your case or not, you should consider using the approach described in that article, or some other with the same idea.

WCF Service call working with basicHttpBinding but fails with netTcpBinding

(Please read comment as i have a fix)
Hi,
I have created a WCF Service that i am hosting in IIS 7.5 on Windows 7 using .net 4.0
The service is hosted both on http and net.tcp.
net.tcp://localhost:42/Service/MyService.svc
http://localhost:43/Service/MyService.svc
I have tested my service using the WcfTestClient and it seems to work correctly through both basicHttp and netTcp.
However, when i try consume this service through my ASP.NET Website, i receive an error when trying to go through nettcp
My client end point looks as follows
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Generic_HttpBinding" sendTimeout="00:01:00" receiveTimeout="00:01:00" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000000">
<security mode="None"/>
<readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000"/>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="Generic_Binding" sendTimeout="00:01:00" receiveTimeout="00:01:00" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000000">
<security mode="None"/>
<readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000"/>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint name="EndPointHttp" address="http://localhost:43/Service/MyService.svc" binding="basicHttpBinding" bindingConfiguration="Generic_HttpBinding" contract="NameSpace.Services.Contracts.IService"></endpoint>
<endpoint name="EndPoint" address="net.tcp://localhost:42/Service/MyService.svc" binding="netTcpBinding" bindingConfiguration="Generic_Binding" contract="NameSpace.Services.Contracts.IService"></endpoint>
</client>
Now i call the service in the exact same way just swapping my end point name
var factory = new ChannelFactory<IService>(SuppliedEndpointName);
factory.Open();
var proxy = factory.CreateChannel();
var result = proxy.SomeServiceMethod();
If i pass this method the basicHttpBinding it works perfectly.
The second i swap to nettcp, i receive this error immediately:
Exception: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:01:00'.
Inner Exception: An existing connection was forcibly closed by the remote host
Error Code: 10054
Please can anyone help me, it driving me crazy.
I have definately installed the WCF HTTP Activation and NON HTTP Activation features.
I have setup my binding to be both HTTP and net.tcp on differen't ports.
I have set my enabled protocols to http,net.tcp in IIS.
I have disabled my firewall.
I have run aspnet_regiis -i for .net 4.0
HELP!
I finally found that changing my security mode to transport fixes the problem.
However my service has it security mode set to none.
So why does my client only works with security mode transport on?
netTcpBinding by default transport security with both signing and encryption. Try removing the security element (<security mode="None"/>).
Also
Ports under 8000 (and definitely under 1024) are normally not safe to be used for services. Try using safe ports.