WCF Service start error - Service has zero application endpoints - c#

I'm trying to start a windows service and I'm getting the following error:
Service cannot be started. System.InvalidOperationException: Service
'LazyPCAndroiderSvc.LazyPCController' has zero application
(non-infrastructure) endpoints. This might be because no configuration
file was found for your application, or because no service element
matching the service name could be found in the configuration file, or
because no endpoints were defined in the service element.
?
I've already tested the service using WCF Tester and it posed no problem. Only when I try to run this as a windows service, it causes the above error.
Here is my app.config from the wcf service:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="LazyPCAndroiderSvc.LazyPCController"
behaviorConfiguration="LazyPCControllerBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8750/LazyPCAndroiderSvc/LazyPCController/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="LazyPCAndroiderSvc.ILazyPCController" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="LazyPCControllerBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I've verified that the names match perfectly (Including the namespace).
Here is my WindowsService code:
namespace LazyPCAndroiderWinSvc
{
public partial class Service : ServiceBase
{
ServiceHost sHost;
public Service()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
sHost = new ServiceHost(typeof(LazyPCAndroiderSvc.LazyPCController));
sHost.Open();
}
protected override void OnStop()
{
sHost.Close();
}
}
}
This seems like a trivial problem but I cannot locate the cause.

Service may not read automatically from LazyPCAndroiderSvc.dll.config - put those configurations in your main exe's App.config

Related

WCF error - Can't get service endpoint up

I started working with WCF recently, and I'm having a problem that I just don't have a clue how to solve.
I start a WCF Service using Service Host, but when I use the URI in a browser it doesn't show the contract of the service, and it gives an exception when I try to connect to it using a ChannelFactory.
I created the project in Visual Studio 2017, and didn't do anything to the config file, excpet changing the base address. Both the service interface and implementation are in the root project "folder", and I've tried disabling the firewall and even my antivirus, but nothing seems to work.
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="TaskExecutor.Exec">
<endpoint address="" binding="basicHttpBinding" contract="TaskExecutor.IExec">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8001/TaskExecutor/Exec/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Service interface:
namespace TaskExecutor
{
[ServiceContract]
public interface IExec
{
[OperationContract]
void DoWork();
}
}
Service implementation:
namespace TaskExecutor
{
public class Exec : IExec
{
public void DoWork()
{
Console.WriteLine("Doing work.");
}
}
}
Program launching the service:
using (ServiceHost host = new ServiceHost(typeof(Exec)))
{
host.Open();
Console.WriteLine("exec service started at {0}", host.BaseAddresses[0]);
}
Console.WriteLine("Press any key to end...");
Console.ReadLine();
After launching the program display the message:
exec service started at http://localhost:8001/TaskExecutor/Exec/
Press any key to end...
The service client code is the following:
EndpointAddress endpoint = new EndpointAddress("http://localhost:8001/TaskExecutor/Exec/");
BasicHttpBinding binding = new BasicHttpBinding();
ChannelFactory<IExec> channelFactory = new ChannelFactory<IExec>(binding, endpoint);
IExec proxy = channelFactory.CreateChannel();
proxy.DoWork();
And it gives the exception:
System.ServiceModel.EndpointNotFoundException occurred
HResult=0x80131501
Message=There was no endpoint listening at http://localhost:8001/TaskExecutor/Exec/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Inner Exception 1:
WebException: Unable to connect to the remote server
Inner Exception 2:
SocketException: No connection could be made because the target machine actively refused it
I seriously don't know what to do, and any help would be amazing.
Thank you very much!
You have exposed metadata but didnt bind it to the service.Here's how you have to.
<behaviors>
<serviceBehaviors>
<behavior name="metadadiscovery">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Now bind the behavior to the service.
<services>
<service name="TaskExecutor.Exec" behaviorConfiguration="metadadiscovery">
<endpoint address="" binding="basicHttpBinding" contract="TaskExecutor.IExec">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8001/TaskExecutor/Exec/" />
</baseAddresses>
</host>
</service>
</services>
Now when you type the address in the browser you should be able to see wsdl.
http://localhost:8001/TaskExecutor/Exec/
So I figured out what was wrong, It was the code starting the service. instead of what I have It should be:
using (ServiceHost host = new ServiceHost(typeof(Exec)))
{
host.Open();
Console.WriteLine("exec service started at {0}", host.BaseAddresses[0]);
Console.WriteLine("Press any key to end...");
Console.ReadLine();
}

Could not find a base address that matches scheme net.tcp for the endpoint with binding MetadataExchangeTcpBinding self hosting

I have created a class library which have Datacontract and service contract and its implementation. Then I created a console application to host the wcf service. Where i have defined WCF setting in app.config file which is below.
<configuration>
<system.serviceModel>
<services>
<service name="TestService.TestService" behaviorConfiguration="tcpbindingConfiguration">
<host>
<baseAddresses>
<add baseAddress="net:tcp://FullComputerName:9002/TestService"/>
</baseAddresses>
</host>
<endpoint address="net:tcp://FullComputerName:9002/TestService" binding="netTcpBinding" contract="TestService.ITestServiceContract"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="tcpbindingConfiguration">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
Then I program.cs File.
ServiceHost sh = null;
try
{
sh = new ServiceHost(typeof(TestService.TestService));
sh.Open();
Console.WriteLine("Service started at net:tcp//FullComputerName:9002/TestService");
}
catch (Exception ex)
{
sh = null;
Console.WriteLine("Service cann't started");
throw;
}
I have activate the WCF for Non HTTP from windows features on and off.
I want to host this wcf service in console application, Some article suggest that i need to set nettcp binding in IIS. Why i do that?
IIS is an alternative hosting for your WCF service, that is you either host it in your console application or in IIS. As far as I understand, there should be no need to setup IIS, if you use a console application.
Try changing "net:tcp" in your configuration to "net.tcp".

"No Endpoint listening" only when consuming WCF via windows service

I have deployed WCF web service in IIS (remote-host: godaddy) and trying to consume through windows service. But getting below error when I try to consume via Windows Service.
"Exception: There was no endpoint listening at http://mydomainname.com/vfolder1/vfolder2/HelloService.svc/HelloService" that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
But when i consume the same service via Windows Form, it works without any issue.
Below is my WCF web service configuration (web.config)
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
<endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://mydomainname.com/vfolder1/vfolder2/"/>
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
Below is my WCF client configuration (app.config)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHelloService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mydomainname.com/vfolder1/vfolder2/HelloService.svc/HelloService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHelloService"
contract="HelloService.IHelloService" name="BasicHttpBinding_IHelloService" />
</client>
</system.serviceModel>
Below is the code in Windows forms
private void button1_Click(object sender, EventArgs e)
{
HelloService.HelloServiceClient client = new HelloService.HelloServiceClient();
label1.Text = client.GetMessage(textBox1.Text);
}
Below is the code in Windows Service
public static void write_data()
{
try
{
HelloService.HelloServiceClient clNt = new HelloService.HelloServiceClient();
for (int i = 0; i < 10; i++)
{
Write_Log(clNt.GetMessage(i.ToString()));
}
clNt.Close();
}
catch (Exception ex)
{
Write_Log("Exception: " + ex.Message.ToString());
}
}
When we initially developed & hosted in local network (IIS), we never had any issues. This is our first project in WCF and involving remote host. Tried to look all similar posts but all were talking on complete non-working. Nothing similar to our scenario exists.
Appreciate the great help.
The issue is resolved. Our company policy wasn't allowing the service to communicate to internet when running under "Local System" privilege. I temporarily changed to run with my user credentials and it went through.

Adding WCF service reference in ASP.NET MVC app fails

I'm trying to add a WCF service to my ASP.NET MVC application. After setting it up, I get an error whenever I want to test it.
Here is my code:
BackgroundTask.svc
public class BackgroundTask : IBackgroundTask
{
public void ShutdownVm()
{
}
public void UpdateTable()
{
}
}
IBackgroundTask.cs
[ServiceContract]
public interface IBackgroundTask
{
[OperationContract]
void ShutdownVm();
[OperationContract]
void UpdateTable();
}
Web.config
<system.serviceModel>
<services>
<service behaviorConfiguration="bgtBehaviour" name="IsolutionsAzureManager.Controllers.BackgroundTask">
<endpoint address="BackgroundTask" binding="basicHttpBinding"
bindingConfiguration="" name="" contract="IsolutionsAzureManager.Controllers.IBackgroundTask" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:44304/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="bgtBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
So, whenever I want to test my WFC service, I get this error:
Error: Cannot obtain Metadata from https://localhost:44304/Controllers/BackgroundTask.svc
Error: The HTML document does not contain Web service discovery information.
Can anyone see the mistake?
Because you are attempting to acquire the mex endpoint over Https, you'll also need to switch to mexHttpsBinding and
to enable the httpsGetEnabled setting:
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
Alternatively, obtain the endpoint via http (http://localhost:44304/Controllers/BackgroundTask.svc) and then just switch back to https once the client has built the service reference artifacts.

WCF NetNamedPipeBinding Service NorthwindService example vs MyService

I have complete exhausted resources on trying to get NetNamedPipeBinding for my WCF Service working. I was able to get the NorthwindService example working found here.
For the NorthwindService example, I have the following:
namespace NorthwindServices
{
public class Customer : ICustomer
{
public string GetCustomerName(int CustomerID)
{
return CustomerID.ToString();
}
}
}
namespace NorthwindServices
{
[ServiceContract]
public interface ICustomer
{
[OperationContract]
string GetCustomerName(int CustomerID);
}
}
And the configuration for the example is the following:
<system.serviceModel>
<services>
<service name="NorthwindServices.Customer"
behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/NorthwindServices/Customer"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="CustomerService" binding="netNamedPipeBinding" contract="NorthwindServices.ICustomer"/>
<endpoint address="CustomerService/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
I have an IIS Site defined for this with the details below:
So when I go to 'Add Service Reference' I can pull in the reference perfectly fine.
However, when I try to do the same in my actual application, I still cannot seem to figure it out. I am unable to pull in the reference.
The site structure is the following:
The top level site is an MVC site, and there is an "API" virtual directory below it where the service resides that I am trying to expose over NetNamedPipeBinding.
The bindings for the site are the following:
The config for the service I am trying to expose over named pipes is the following:
<system.serviceModel>
<services>
<service name="Site.API.Service.WorkItemQueueService"
behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/WorkItemQueueService"/>
</baseAddresses>
</host>
<endpoint address="QueueService"
binding="netNamedPipeBinding"
contract="Site.API.Service.IWorkItemQueueService"/>
<endpoint address="QueueService/mex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True"/>
The service implementation is the same as the customer service above, but obviously renamed to match the configuration above.
When I try to add a service reference, or find the metadata for this, It cannot find it.
IMPORTANT - All of the pre configuration items such as starting the Net Pipe listerner and role service have been completed, hence the NorthwindServices example works.

Categories