Wcf decrease client connection timeout - c#

I have a wcf service that works fine. The problem is the client. I have a little gui where the user is supposed to place the ip address of where the wcf service is located. Both the client and service are on the same network so if I am not able to connect it is because I provided an incorrect ip address or because the firewall is blocking. Anyways how can I shorten that time so that if the user types the incorrect ip he does not have to wait like 20 seconds? Here is how my app.config file looks for my client:
Here is how my client app.config file looks:
<client>
<endpoint address="net.tcp://127.0.0.1:41236/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
Edit
I have updated my app.config file to:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" sendTimeout="00:00:02" receiveTimeout="00:00:02">
<security mode="Transport" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://10.10.1.154:41236/"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1"
contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
note I am placing an ip address that does not exist on purpose and for some reason the program still waits for like 10 seconds... I added sendTimeout="00:00:02" receiveTimeout="00:00:02" attributes and still did not work :(
Edit 2
Here is the error message that I get:
Could not connect to net.tcp://10.10.1.154:41236/. The connection
attempt lasted for a time span of 00:00:21.0342031. TCP error code
10060: A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond 10.10.1.154:41236.
Note it attempted to connect for 21 seconds... I knew I was not going to be able to connect but it will be nice if I could reduce that time. I am planning to use this program on the same network...

On your NetTcpBinding_IService1 bindingConfiguration
add an attribute sendTimeout="00:00:02"
This will reduce it to 2 seconds.
Edit
Please use OpenTimeout="00:00:02" this should work.

replace timeout in your bindingConfiguration NetTcpBinding_IService1

An answer for this has been given here wcf-channelfactory-and-opentimeout. It has something to do with sockets timeout. It seems that a workaround is needed.

Related

Use URL to call wcf service instead of ip or localhost

I hosted my WCF service on one static IP but when net disconnected then dynamic IP of system changes so my service stop working.
Now what I want to do is instead of using IP address or localhost I want to call service using URL.
This is my web.con file code for
<system.serviceModel>
<services>
<service name="abc.bca" behaviorConfiguration="mexendpoint">
<endpoint address="" binding="basicHttpBinding" contract="abc.Ibca">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/bca.svc" />
</baseAddresses>
</host>
</service>
</services>
And this is how I define an IP address for calling through mobile application suppose that below is my static IP.
117.87.21.12
So instead of call static IP can I redirect it to any URL like techit#.com
The issue is more related to Domain Name System. Generally, we could call the service with the computer name.
http://myserverhostname:xxx/service.svc
If we want to add the custom domain name, we should have an understanding on the DNS system,
https://en.wikipedia.org/wiki/Domain_Name_System
https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/reviewing-dns-concepts
For example, we want to access the computer with a bespoke name, we should ensure it located in the right dns name since the Domain Name System is recursively analyzed.
One more thing I want to share with you is the local “Hosts” file will be used preferentially when the domain name is resolved. Therefore, we could achieve it by add an entry to the file ( located in the System32/drivers/etc/hosts file). You could refer to the below link.
https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
Feel free to let me know if there is anything I can help with.

WCF response is truncated when calling through web server

There is a webservice (that I don't control) that returns a large response. In a simple console application the call to the service returns of the expected data. However when I do the same in a web application, some of the data is missing.
If I serialize the response and write it to a file, one file is 215mb and the other 117mb (they should be the same size).
The web service bug occurs both on my local maching and on the production web server.
No errors are being thrown. I have run a WCF trace and is shows no errors or warnings. There is nothing logged in the event log.
The <system.serviceModel> config section is exactly the same between the two applications.
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_Service" maxReceivedMessageSize="2147483647" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://myService/Service.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_Service" contract="MyService.Service"
name="WSHttpBinding_Service">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
There are several possibilities:
If the data was getting truncated you would have a malformed xml, which Would result in an exception.
If the web server was not using the correct config file and it did not allow the size of response you would get an exception.
In both of the above cases you would not be able to serialize the result.
So you are getting a wellformed xml back, but it is a different size. Then there are 2 possibilities:
A difference in the encoding, that affects the size
A difference in the request parameters, that affects what is returnned

Hosting WCF on IIS - EndpointNotFoundException

After implemeting a WCF service, hosting it on the IIS Server, it returned with the below error.
EndpointNotFoundException was unhandled by user code There was no
endpoint listening at XXXXX that could accept the message. This is
often caused by an incorrect address or SOAP action. See
InnerException, if present, for more details.
That service is identically has the same implementation and configuration of 5 running services with no errors.
when I tried to figure out what is going on the IIS server, the below screenshot.
So it seems that this specific service has no detected Contract. although I'm using the same configuration as below.
<service name="XX.XX.Provisioning.EldaftarManagementService">
<endpoint address="" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" bindingNamespace="http://XX.XX.com/XX/" contract="XX.XX.Provisioning.Eldaftar.IEldaftarManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="ProvisioningBasicBinding" bindingNamespace="http://XX.XX.com/provisioning/" contract="XX.XX.Provisioning.Eldaftar.IEldaftarManagementService" />
</service>
<service name="XX.XX.Provisioning.Common.UserManagement.UserManagementService">
<endpoint address="" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" bindingNamespace="http://XX.XX.com/XX/" contract="XX.XX.Provisioning.Common.UserManagement.IUserManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="ProvisioningBasicBinding" bindingNamespace="http://XX.XX.com/provisioning/" contract="XX.XX.Provisioning.Common.UserManagement.IUserManagementService" />
</service>
Kindly noted that when accessing the service.svc url it replies normally and the wsdl is shown. So that means it's hosted fine on the IIS.
Do I miss something?
Update:
Client config.
<endpoint address="https://XXX/EldaftarManagementService.svc" behaviorConfiguration="ProvisioningClientBehaviour" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" contract="EldaftarManagementService.IEldaftarManagementService" />
<endpoint address="https://XXX/UserManagement.svc" behaviorConfiguration="ProvisioningClientBehaviour" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" contract="UserManagementService.IUserManagementService" />
i notice sometime after reconfigure my service reference, the client config getting wsdl with server name. then i get EndpointNotFoundException exception.
example :
service reference is : http://192.168.61.2:1111/Service1.svc
but in the config endpoint address it show : http://serverName:1111/Service1.svc
After i change the config endpoint address with the service reference address , then it resolved. Not sure why but now every time when i reconfigure the endpoint address, i will manually change the config endpoint address to make sure it get the same address.

Failed to invoke the service. Possible causes: The service is offline or inaccessible while Invoking

I have my service configured as below:
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:808/service" />
</baseAddresses>
</host>
<endpoint address="net.tcp://127.0.0.1:808/service/"
binding="netTcpBinding"
contract="WcfService1.IService1"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add scheme="net.tcp" binding="netTcpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
and the client as:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" sendTimeout="00:05:00" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://127.0.0.1/service/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="IService1"
name="NetTcpBinding_IService1">
<identity>
<servicePrincipalName value="host/MachineName" />
</identity>
</endpoint>
</client>
</system.serviceModel>
When using WCFTestClient or SVCutil, I am able to discover and access the servie and generate proxy or stubs.
But when I want to invoke any of the methods getting following error:
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
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:04:59.9980468'.
Set the following value inside the endpoint block
<identity>
<dns value ="localhost"/>
</identity>
Maybe not the answer you are looking for, but for development on the local machine I always use an HTTP endpoint. I find Net.TCP will only play nice when it is hosted on a server in IIS.
It is easy enough to add the NET.TCP endpoints once you deploy to an IIS server. Note: that the base address no longer has any affect as that is set in IIS. To test the new endpoints it is best to start by opening the service in a browser while remoted into the server, that way you get the best error messages.
If i understand correctly you are trying to select the endpoint when creating the service reference? Thats now how it works.
If you create your service reference using 127.0.0.1/service/Service1.svc
You should see in your config file something like the following. (When I create my service endpoints I always name them with the protocol as a suffix.
<endpoint address="http://servername:8090/servername/servername.svc/Business"
binding="basicHttpBinding" bindingConfiguration="BusinessHTTP"
contract="servername.IService" name="BusinessHTTP" />
<endpoint address="net.tcp://servername:8030/Service/Service.svc/Business"
binding="netTcpBinding" bindingConfiguration="BusinessTCP"
contract="servername.IService" name="BusinessTCP" />
then in your code you can choose which endpoint to use.
Dim svc as New SeviceReferenceName.BusinessClient("BusinessTCP")"
I have faced the same issue. It was the issue of port address of EndpointAddress. In Visual studio port address of your file (e.g. Service1.svc) and port address of your wcf project must be the same which you gives into EndpointAddress. Let me describe you this solution in detail which worked for me.
There are two steps to check the port addresses.
In your WCF Project right click to your Service file (e.g. Service1.svc) -> than select View in browser now in your browser you have url like http://localhost:61122/Service1.svc so now note down your port address as a 61122
Right click your wcf project -> than select Properties -> go to the Web Tab -> Now in Servers section -> select Use Visual Studio Development Server -> select Specific Port and give the port address which we have earlier find from our Service1.svc service. That is (61122).
Earlier, I had a different port address. After specifying the port address properly, which I got from the first step, EndpointAddress 61122, my problem was solved.
I hope this might be solved your issue.
NetTcp binding is secured by default.In the security authentication process between client and service,WCF ensures that the identity of service matches the values of this element. Therefore service need to be configured with :
<identity>
<dns value ="localhost"/>
</identity>

Named Pipe Quota problem

I have a problem transmitting a file-sized thingy through WCF which uses the named pipe binding
<netNamedPipeBinding>
<binding name="largeMessage"
maxBufferPoolSize="524288000"
maxReceivedMessageSize="655360000"
maxBufferSize="655360000" >
<readerQuotas maxStringContentLength="655360000"
maxArrayLength="2000001"
maxBytesPerRead="2000001"
maxNameTableCharCount="2000001" />
</binding>
</netNamedPipeBinding>
and this is the service definition
<service name="BusinessService.TaskService"
behaviorConfiguration="BusinessService.TaskServiceBehavior">
<endpoint
address=""
behaviorConfiguration="customEndPointBehavior"
binding="netNamedPipeBinding"
bindingConfiguration="largeMessage"
contract="BusinessServiceContracts.Services.ITaskService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
as can be seen, i've set quite large values for all quotas i've been able to find, and still, i get the "The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element." error in the WCF trace files.
I'm fresh out of ideas where to look next, so has anyone else run into the same or similar problem?
The client configuration was (more or less) the same, but the darn thing just wouldn't work.
But, after I opened the server .config with the WCF Configuration Editor, made no changes, and saved, it magically started working, so my guess is that I had some sort of tag mix-up in the file.
Sorry to bother you.
You probably have two configuration files: one from service implementation, and another for your client application; Can you please post both configurations?
Besides, please read this article: Making Sense of Transport Quotas
OK, you've posted the server-side configuration with the <services> node - look fine to me. How about the client-side configuration? You would have to have something in the <client> node as well - does that reference the same binding configuration as well?
Marc

Categories