Can't add service reference to net tcp wcf service
Solution 1
Michael, this is a net.tcp binding that I typically use for a WCF service.
<bindings>
<netTcpBinding>
<binding name="TcpBinding"
receiveTimeout="Infinite"
sendTimeout="Infinite"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<reliableSession inactivityTimeout="Infinite"/>
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
Try to add it to your configuration:
<service name="WcfServiceLibrary1.Service1">
<endpoint
address=""
binding="netTcpBinding" bindingConfiguration="TcpBinding"
contract="WcfServiceLibrary1.IService1">
...
Also, my services are running under ServiceAccount.LocalSystem
.
Check
netstat -ap tcp
if the service is listening.
EDIT: my Service class below. Note that the current directory of the windows service is set programatically to the BaseDirectory, i.e. the directory of the executable.
public class Service : ServiceBase
{
public static void Main()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
ServiceBase.Run(new Service());
}
...
}
Solution 2
You've specified a behavior but haven't given it a name. Give the behavior a name and point to it using behaviorConfiguration in your service.
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="svc1behavior">
...
<serviceBehaviors>
<behavior name="svc1behavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
Michael
Updated on June 14, 2022Comments
-
Michael almost 2 years
I have a WCF service hosted on my local machine as windows service. Now I'm trying to add a service reference in the client (again on my local dev machine) but I'm getting an error
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8523/Service1'. Could not connect to net.tcp://localhost:8523/Service1. The connection attempt lasted for a time span of 00:00:02.0011145. TCP error code 10061: No connection could be made because the target machine actively refused it
I checked that the Windows firewall doesn't block port 8523. I even created a new rule in Windows firewall to allow run 8523 port. But when I'm running
netstat -sp tcp
I can't seem to find port 8523. But I can see Serice1 service's state is set to START in Services. This is the config filesService Library
<system.serviceModel> <services> <service name="WcfServiceLibrary1.Service1"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="WcfServiceLibrary1.IService1"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:8523/Service1" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
Config in the windows service project looks identical.
-
Richard Blewett over 12 yearsif you're using .NET4 you don;t need to name behavior blocks-an unnamed behavior block acts as a default behavior configuration for services
-
Michael over 12 yearsSorry for late response, tried it as well Clemens, but still can't seem to create client for service.
-
Clemens over 12 yearsAnd do you see the service listening on port 8523?
-
Michael over 12 yearsNope Clemens, thats the problem, I can't seem that port 8523 is running, so I changed the windows service with Console application, in particular, now Console Application is hosting service, and this works as expected, but I can't understand why, because both - windows service and console application are using same dll's of service and same configuration. So why I can host my service using Console Application but can't host it via Windows Service ? Any clues ?
-
Clemens over 12 yearsIs the service running under ServiceAccount.LocalSystem?
-
Michael over 12 yearswell currently it's running under NetworkService account, but I followed your approach, and changed it to run under Local System, but nothing changed. I've even changed it to run under my account ( I'm admin on my dev machine ) but no luck so far.
-
Clemens over 12 yearsMichael, take a look at the extended sample code in my answer. In the Main method of my ServiceBase-dericed class i set the current working directory. Otherwise the service won't find its configuration file.
-
Michael over 12 yearsI've included config files all over the place, in windows service application, in the bin folder ( with WindowsService1.exe file ), same config file resists in the Service project itself ( again in the bin/Debug I've included config's as well ). Do you think this is still necessary ?
-
Clemens over 12 yearsAFAIK a Windows service uses C:\Windows\System32 as current working directory by default, no matter where it is installed. So you must programatically set the cwd to that directory that contains your config file. This is usually the same directory as where the executable resides, i.e. AppDomain.CurrentDomain.BaseDirectory
-
Clemens over 12 yearsMichael, are you still trying to solve this, i.e. did you try to set the service's cwd?
-
Michael over 12 yearsNope, sorry for making you wait for my response. We decided to host it under IIS 7. But I'll try it as soon as I have free time, I'm curious as well, what was the problem. Thanks for support.