WCF Service over netTCPBinding timing out for Clients in LN, working fine for Clients in US - wcf

I have a WCF Service exposed via TCPbinding running on a server in NY. I have no issues connecting to the service and getting back the results from clients connecting to this service from Americas but having issues for clients from London/Europe. I am not quite sure why this timeout issue happens but below are by Client and Server settings.
Server
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="TCPBinding_IDataService"
receiveTimeout="00:20:00"
openTimeout="00:05:00"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
maxConnections="10"
maxBufferSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Message">
<message clientCredentialType="Windows"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="DataServiceBehavior" name="DIT.Data.DRD.Service.PIERDataService">
<endpoint address="DataService" binding="netTcpBinding" bindingConfiguration="TCPBinding_IDataService"
contract="DIT.Data.DRD.Service.IPIERDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="MEX" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9100/DRDService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceBehavior" >
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="false"/>
<dataContractSerializer maxItemsInObjectGraph="61200000" />
<serviceThrottling maxConcurrentCalls="100"
maxConcurrentInstances="1000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics performanceCounters="Default">
<messageLogging logEntireMessage="true" logMalformedMessages="false"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" />
</diagnostics></system.serviceModel>
My client has the following settings in C# code
private DataServiceClient GetClient(string uri, int? timeout)
{
EndpointAddress endpointAddress = new EndpointAddress(new Uri(uri),
EndpointIdentity.CreateDnsIdentity("localhost"),
new System.ServiceModel.Channels.AddressHeaderCollection());
NetTcpBinding svcBinding = new NetTcpBinding();
svcBinding.Security.Mode = SecurityMode.Message;
svcBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
svcBinding.MaxReceivedMessageSize = 2147483647;
svcBinding.MaxBufferPoolSize = 2147483647;
svcBinding.MaxBufferSize = 2147483647;
svcBinding.MaxConnections = 10;
svcBinding.ReaderQuotas.MaxBytesPerRead = 2147483647;
svcBinding.ReaderQuotas.MaxDepth = 2147483647;
svcBinding.ReaderQuotas.MaxArrayLength = 2147483647;
svcBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
svcBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
if (timeout.HasValue)
svcBinding.SendTimeout = svcBinding.ReceiveTimeout = new TimeSpan(0, timeout.Value, 0);
else
svcBinding.SendTimeout = svcBinding.ReceiveTimeout = new TimeSpan(0, 5, 0); // this is default
PIERDataServiceClient dsc = new PIERDataServiceClient(svcBinding, endpointAddress); //this is wcf client from ClientBase
return dsc;
}
Can someone having experience with WCF timeout issues shed some light on this? I've been trying to follow the gzillion posts on various forums but the understanding I gathered and implementation in the form of code and configuration is not helping much.
TIA,
Shravan

Related

What is the default timeout for the basichttpbinding in wcf

I am new to wcf, created a service and a consumer. As documentation suggest, default timeout is 10 minutes for ReceiveTimeout.
In consumer side, i tried to reproduce for timeout for the request but event after 25 minutes it works without breaking.
If someone can let me know what exactly the time we can open a channel with basichttp binding?
Below is the wcf app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Raj">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="">
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Raj">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WCF_NewsService.News_Service" behaviorConfiguration="Raj">
<host>
<baseAddresses>
<add baseAddress="https://localhost:8732/Design_Time_Addresses/WCF_NewsService/News_Service/"/>
</baseAddresses>
</host>
<endpoint address="News_Service" binding="basicHttpBinding" contract="WCF_NewsService.INews_Service" bindingConfiguration="Raj"/>
</service>
</services>
</system.serviceModel>
Consumer Code:
var myBinding = new BasicHttpBinding();
myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Certificate;
myBinding.MaxReceivedMessageSize = Int32.MaxValue;
myBinding.MaxBufferSize = Int32.MaxValue;
BindingParameterCollection bindingParameters = new BindingParameterCollection();
var address = new EndpointAddress("https:xxxx:8732/Design_Time_Addresses/WCF_NewsService/News_Service/News_Service");
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
//Client Credentials
string _thumbPrint = "5AD9BC96AA4D44852D1B97C91C1628C070E3187C";
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, _thumbPrint);
bindingParameters.Add(clientCredentials);
var factory = myBinding.BuildChannelFactory<IRequestChannel>(bindingParameters);
factory.Open();
var irc = factory.CreateChannel(address);
// --- Without body
Message createRequestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/INews_Service/Getnews");
irc.Open();
var result = irc.Request(createRequestMessage);
Thread.Sleep(TimeSpan.FromMinutes(25));
//--With body
TOInews tOInews = new TOInews { ID = 125, Body = "this is body test", Header = "This is header test" };
createRequestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/INews_Service/GetnewsById", tOInews);
//irc.Open();
var result1 = irc.Request(createRequestMessage);
ReceiveTimeout – used by the Service Framework Layer to initialize the session-idle timeout which controls how long a session can be idle before timing out.
I didn't find that you have ReceiveTimeout configured in the config file, you need to configure it.You can see the code below.You can check the documentation on how to configure the timeout value on the binding.
You can use Message Inspectors to capture WCF operation execution time. See this post for specific steps.
<basicHttpBinding>
<binding name="Raj" openTimeout="00:10:00"
closeTimeout="00:10:00"
sendTimeout="00:10:00"
receiveTimeout="00:10:00">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="">
</transport>
</security>
</binding>
</basicHttpBinding>

Disable CustomUserNamePasswordValidator for specific operation

I am using a CustomUserNamePasswordValidator for my WCF web service. However, i am trying to add a IsAlive operation, which should be able to be called from clients, even when not authenticated.
For example, i want to be able to do a check, if a service is online and accessible on startup, so i can notify the user on missing inet connection or a not available service (due to maintenance).
I have code for all this already in place. What i am missing is how i can access the operation without passing a username and password.
I could probably just add a second service which allows anon access, but i'd really prefer to use the existing service.
The Validator is implemented like this (i ommited the actual checking code):
public sealed class MyCredentialValidator : UserNamePasswordValidator
{
public MyCredentialValidator ()
{
}
public override void Validate(string userName, string password)
{
Debug.WriteLine("MyCredentialValidator : Validate called.");
// do some checks
var isValid = CheckCredentials(userName, password)
if(!isValid)
{
throw new FaultException(...);
}
}
}
It is registered in the web.config like so:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SecureBehavior">
<serviceMetadata httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyCredentialValidator,..."/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="SecureBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxStringContentLength="2147483647"/>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="my service" behaviorConfiguration="SecureBehavior">
<endpoint address="" binding="wsHttpBinding" contract="my contract" bindingConfiguration="SecureBinding">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
client side configuration:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SecureBinding"
closeTimeout="00:10:00"
openTimeout="00:10:00"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxStringContentLength="2147483647"/>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://my service url"
contract="my contract"
binding="wsHttpBinding"
bindingConfiguration="SecureBinding"
name="secure" />
</client>
</system.serviceModel>
client side wcf call code:
var cf = new ChannelFactory<my contract>("secure");
using (IClientChannel channel = (IClientChannel)cf.CreateChannel())
{
channel.OperationTimeout = TimeSpan.FromSeconds(3);
bool success = false;
try
{
channel.Open();
result = ((my contract)channel).IsAlive();
channel.Close();
success = true;
}
finally
{
if (!success)
{
channel.Abort();
}
}
}
I have done something like this before,
depending on how you have integrated your custom validator in the wcf pipleline,
you could simply before you do the actual validation, which I guess returns something like true or false, you could check the incoming url or address and see if it is going to be going to your IsAlive operation, if that is the case, you could simply do a early return true.
Wcf has a few ways with which you can check what operation the client has called.
to be more accurate, I would need to know how you wrote your custom validator and where in the pipeline it integrates.

Silverlight WCF call is too large for sharepoint wcf

I have a silverlight 4 project calling a WCF service deployed on sharepoint 2010.
There are two methods a get and and a save,
teh get works fine but the save returns a generic message "Not Found"
The save is passing a large object with 2 lists. If I reduce the size of the list it all works.
So I figure I have to increase the maxReceivedMessageSize, this is easily done on the silverlight side just edit ServiceReferences.ClientConfig.
however I dont know where to do it on teh server side
Where is the binding information on the shaprepoint webserver.
I've had a look in \inetpub\wwwroot\wss\VirtualDirectories\80\web.config and it isn't there.
is there an easy way to get the binding info from teh URL?
I tried to setup some bindings for it but I just get errors
my attempt is
<bindings>
<basicHttpBinding>
<binding name="MyDemoBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyDemoBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyDemoBehavior" name="BEIM.Webservices.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyDemoBinding" contract="BEIM.Webservices.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress=”http://localhost/_vti_bin/BEIM.Webservices” />
</baseAddresses>
</host>
</service>
</services>
got the answer from here
private static void ConfigureWebService()
{
SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
SPWcfServiceSettings wcfServiceSettings = new SPWcfServiceSettings();
wcfServiceSettings.ReaderQuotasMaxStringContentLength = 10485760;
wcfServiceSettings.ReaderQuotasMaxArrayLength = 2097152;
wcfServiceSettings.ReaderQuotasMaxBytesPerRead = 10485760;
wcfServiceSettings.MaxReceivedMessageSize = 10485760;
// must be in lower case
contentService.WcfServiceSettings["service.svc"] = wcfServiceSettings;
contentService.Update();
}
I just ran it from a console app

WCF Initiation is taking too much time

WCF service is taking around 5-6 seconds for first request there after all call execute very fast.
below is the client side configuration for my WCF service.
Using IIS hosting.
WSHttpBinding binding = new WSHttpBinding();
binding.SendTimeout = TimeSpan.FromMinutes(1);
binding.OpenTimeout = TimeSpan.FromMinutes(1);
binding.CloseTimeout = TimeSpan.FromMinutes(1);
binding.ReceiveTimeout = TimeSpan.FromMinutes(1);
binding.AllowCookies = false;
binding.BypassProxyOnLocal = false;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.MessageEncoding = WSMessageEncoding.Mtom;
binding.TextEncoding = System.Text.Encoding.UTF8;
binding.UseDefaultWebProxy = true;
binding.Name = "BasicHttpBinding_ILearningService";
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Transport.Realm = "";
Server side configuration
<services>
<service behaviorConfiguration="LearningServiceServiceBehavior" name="LearningService">
<host>
<baseAddresses>
<add baseAddress="https://xxxxx/LearningService.svc" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="ILearningSuiteService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity" messageEncoding="Mtom" sendTimeout="00:1:00" openTimeout="00:2:00">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="LearningServiceServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" httpGetUrl="http://xxxxxxx/Metadata" httpsGetUrl="https://xxxxxxxx/Metadata" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
The other issue you may be see is that as you are using transport security you are doing certificate validation on the client each time you create a new proxy. Is it possible the certificate validation is expensive, say, due to the revocation list for the certificate not being available in a timely fashion?
Try turning off security and see if that changes the behavior
Although not completely definite it looks like you are IIS hosting (I say not definite because baseAddresses are not specified by you in IIS hosting, rather the actual .svc file is the base address for the service)
Assuming you are IIS hosting are you seeing the spin up time for the worker process? Depending on which version of Windows you are using you could use Windows Server AppFabric to autostart the service before the first request
The first time you make the call, the client sets up the connection to the server and the server does necessary authentication, this can take some time.
And based on what I found in my project, the WCF serialization can take much time in the first time if your contract is huge. After that, the serialization can be much quicker.

In WCF, for a webHttpBinding, how do I specify credentials in the client side web.config when the server is using basic authentication?

I have two WCF RESTful services - the "general" service is public and has no security; the "admin" service I intend to use basic authentication over SSL. This is my server side web.config:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="general" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="admin" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyNamespace.AppServices.GeneralService">
<endpoint address="" binding="webHttpBinding" contract="MyNamespace.Contracts.IGeneralService" behaviorConfiguration="web" bindingConfiguration="general" />
</service>
<service name="MyNamespace.AppServices.AdminService">
<endpoint address="" binding="webHttpBinding" contract="MyNamespace.Contracts.IAdminService" behaviorConfiguration="web" bindingConfiguration="admin" />
</service>
</services>
</system.serviceModel>
On the client side, I currently have code that looks like this:
private static IGeneralService GetGeneralChannel()
{
WebHttpBinding binding = new WebHttpBinding();
binding.Security.Mode = WebHttpSecurityMode.None;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
WebChannelFactory<IGeneralService> cf = new WebChannelFactory<IGeneralService>(binding, new Uri("http://localhost:1066/GeneralService"));
IGeneralService channel = cf.CreateChannel();
return channel;
}
private static IAdminService GetAdminChannel()
{
WebHttpBinding binding = new WebHttpBinding();
binding.Security.Mode = WebHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
WebChannelFactory<IAdminService> cf = new WebChannelFactory<IAdminService>(binding, new Uri("http://localhost:1066/AdminService"));
cf.Credentials.UserName.UserName = "myUserName";
cf.Credentials.UserName.Password = "myPassword";
IAdminService channel = cf.CreateChannel();
return channel;
}
The question is, since I obviously do not want to hard-code all of this configuration information, how do I need to provide it in the web.config on the client? It is pretty clear to me that the binding element needs to look pretty much the same on the client as it does on the server. However, where do I indicate the credentials that are assigned to the WebChannelFactory?
Any help and/or insight will be appreciated.
Thanks,
Steve
You cannot put those credentials (username and password) into web.config and have WCF read them from there. This is one of the very few features in WCF which cannot be done in config - you have to set those credentials in your code.
Of course, in your code, you can read them from e.g. a database table, or a config entry somewhere - but you have to do that yourself. WCF can't be configured to automagically read those settings from somewhere.