No connection can be made because the target machine actively rejected it 127.0.0.1:8000

I created a WCF service and tried to host the Managed Windows Service (after the article ). The service works and works in services.

When I try to add a URL to the client application (net.tcp: // localhost: 8000 / UserManagement) I get an error message:

Metadata contains a link that cannot be resolved: 'Net.tcp: // local: 8000 / UserManagement. Failed to connect to net.tcp: // local: 8000 / UserManagement. The connection attempt continued for a period of time 00: 00: 00.9531433. TCP error code 10061: No connection can be made because the target machine actively refused it 127.0.0.1:8000. The connection cannot be made because the target machine actively refused it 127.0.0.1:8000 If the service is defined in the current solution, try creating a solution and adding the service link again.

Service.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.ServiceModel; using System.ServiceProcess; using System.Configuration; using System.Configuration.Install; namespace AddUser { public class UserManagement : IUserManagement { public bool AddUser(string strName, DateTime dtDOB, string strGender, string strRole) { return true; } } [ServiceContract] public interface IUserManagement { [OperationContract] bool AddUser(string strLname,string strFName, string strUname, string strPswd, DateTime dtDOB, string strGender, string strRole, string strHobbies); } public class UserManagementService : ServiceBase { public ServiceHost serviceHost = null; public UserManagementService() { ServiceName = "WCFUserManagementService"; } public static void Main() { ServiceBase.Run(new UserManagementService()); } protected override void OnStart(string[] args) { if (serviceHost != null) { serviceHost.Close(); } serviceHost = new ServiceHost(typeof(UserManagementService)); serviceHost.Open(); } protected override void OnStop() { if (serviceHost != null) { serviceHost.Close(); serviceHost = null; } } } [RunInstaller(true)] public class ProjectInstaller : Installer { private ServiceProcessInstaller process; private ServiceInstaller service; public ProjectInstaller() { process = new ServiceProcessInstaller(); process.Account = ServiceAccount.LocalSystem; service = new ServiceInstaller(); service.ServiceName = "WCFUserManagementService"; Installers.Add(process); Installers.Add(service); } } } 

app.config:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service behaviorConfiguration="AddUser.UserManagementServiceBehavior" name="AddUser.UserManagement"> <endpoint address="" binding="netTcpBinding" contract="AddUser.IUserManagement"/> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:8000/UserManagement" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="AddUser.UserManagementServiceBehavior"> <serviceMetadata httpGetEnabled="false"/> <serviceDebug includeExceptionDetailInFaults="False"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 
+4
source share
2 answers

You need to use the address

 net.tcp://localhost:8000/UserManagement/mex 

when you set up your service link.

Alternatively, the metadata endpoint should use mexHttpBinding , and you should set the httpGetEnabled parameter to true in your service

 <serviceMetadata httpGetEnabled="true"/> 
+1
source

I also ran into the same issue after the following MSDN link that you provided. There is an error in this code.

In your OnStart method

 serviceHost = new ServiceHost(typeof(UserManagementService)); 

instead of creating a ServiceHost for the UserManagementService, use your actual WCF service class name. This line of code will instantiate the Windows service, not the WCF service. I was able to fix it using this.

+1
source

Source: https://habr.com/ru/post/1389629/


All Articles