wcf service host run only on port number 8080 - c#

I have a wcf service and used a console app as the host for my service. when I use base address like this: <baseaddres ="http://ipaddress:8080/" />. When I check my service operation through a web browser I can open the service WSDL and it works fine.
But, as I change the port number to something else. The service host starts fine (with no exception of used port number or anything else). As I go to check if the service is running through web browser the service is not shown. eventually my client also could not locate the service.
app.config configuration
<services>
<service name="Natatorium_WCF.NatatoriumService"
behaviorConfiguration="ServiceBehavior">
<endpoint address="NatatoriumService"
binding="wsHttpBinding"
contract="Natatorium_WCF.INatatoriumService"
bindingConfiguration="wsHttpBindingConfig">
</endpoint>
<endpoint address="NatatoriumService"
binding="netTcpBinding"
contract="Natatorium_WCF.INatatoriumService"
bindingConfiguration="netTcpBindingConfig" >
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://[ServerName]:[PortNO.1]"/>
<add baseAddress="net.tcp://[ServerName]:[PortNO.2]"/>
</baseAddresses>
</host>
</service>
</services>
this is the host code to start the service (console application).
static void Main(string[] args)
{
ChangeServerConfigFileAttributeValue("8080", "8090");
using (ServiceHost host = new ServiceHost(typeof(Natatorium_WCF.NatatoriumService)))
{
host.Open();
Console.WriteLine("Listening...");
Console.ReadLine();
}
}

<configuration>
<system.serviceModel>
<services>
<service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
<endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService" ></endpoint>
<endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService" ></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/"/>
<add baseAddress="net.tcp://localhost:8090/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<remove name="serviceDebug"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>

Related

Can't launch service with net.tcp binding error 10049

I have a problem with launching a WCF service using net.tcp endpoints. I'm getting an 10049 error.
My app.config:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour0"
name="Tinkl.Server.Services.Authentication.AuthenticationService">
<endpoint name="httpEndpoint"
address="reg"
binding="basicHttpBinding"
contract="Tinkl.Server.Services.Authentication.IRegistrationService" />
<endpoint name="httpEndpoint"
address="auth"
binding="basicHttpBinding"
contract="Tinkl.Server.Services.Authentication.IAuthorizationService" />
<!--
<endpoint name="tcpEndpoint"
address="net.tcp://78.26.210.203:50050/reg"
binding="netTcpBinding"
contract="Tinkl.Server.Services.Authentication.IRegistrationService" />
<endpoint name="tcpEndpoint"
address="net.tcp://78.26.210.203:50051/auth"
binding="netTcpBinding"
contract="Tinkl.Server.Services.Authentication.IAuthorizationService" />
-->
<endpoint name="mexEndpoint"
address="mex"
binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://78.26.210.203:50076/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour0">
<!--<serviceMetadata />-->
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
There are 2 endpoints with netTcpBinding and 2 same exact with basicHttpBinding.
The problem appears when I'm trying to use netTcpBinding endpoints, I'm getting an error, but with basicHttpBinding it works fine...
I'm hosting the WCF service in a console application.
Program code
ServiceHost authenticationHost = new ServiceHost(typeof(AuthenticationService));
authenticationHost.Open();
Console.WriteLine("close <ENTER>\n");
Console.ReadLine();
authenticationHost.Close();
Maybe someone faced a similar problem?
If needed, I will give all the necessary additional information
Thank you in advance!
Try to replace lines
net.tcp://78.26.210.203:50050/reg
with
net.tcp://localhost:50050/reg
And the same for /auth endpoint.

Cant connect to WCF Service. Missing EndPointElemt

i'm trying to create my own WCF service and client. I've created my Service with the following app.config settings:
<system.serviceModel>
<services>
<service name="Interface.MyWCFService">
<endpoint address="http://localhost:9999/MyService" binding="basicHttpBinding"
bindingConfiguration="" name="MyServiceEndpoint" contract="Interface.IMyWCFService" />
</service>
</services>
</system.serviceModel>
The service starts without an exception.
My client should connect to this service. His app.config is this one:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:9999/MyService" binding="basicHttpBinding"
bindingConfiguration="" contract="Interface.IMyWCFService"
name="MyServiceEndpoint" kind="" endpointConfiguration="" />
</client>
</system.serviceModel>
</configuration>
In the c# code i try to create a channelfactory in the client.cs with the following code:
ChannelFactory<IMyWCFService> channelFactory = new ChannelFactory<IMyWCFService>("MyServiceEndpoint", new EndpointAddress("http://localhost:9999/MyService"));
IMyWCFService proxy = channelFactory.CreateChannel();
This is not working. Every time i try to start the program i get the following exception:
No Endpointelement with the name "MyServiceEndpoint" and contract
"Interface.IMyWCFService" was found in
ServiceModel-Clientconfigurationsection.
I hope you can help me.
This is how I have my service configured:
<service name="foo.bar.BlaService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/BlaService" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="foo.bar.IBlaService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
And here the client:
<client>
<endpoint name="BlaService" address="http://localhost/BlaService" binding="basicHttpBinding" contract="foo.bar.IBlaService" />
</client>

WCF self hosting Service run ConsoleApp.exe dosn´t work but inside vs2012 well

i got a noopy problem, if i run my self hosted WCF (WCF service Lib + console app) service inside VS everything works fine.
if i want to run the consoleapplication.exe in the project dir, it looks like everything works fine, but it doesn´t. (i´m new to c#)
I`ve tested:
to run it as admin (firewall off and on)
to reservate my service via http urlacl
Works fine means that i can access my service remotely.
Works not fine means that i not evan can access it through localhost.
Are there any dependencies missing?
Thank you in advance!
App.config of the consoleApp:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"
policyVersion="Default" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="SampleEmpServiceLib.EmpService">
<clear />
<endpoint address="basic" binding="basicHttpBinding" contract="SampleEmpServiceLib.IEmpService"
listenUriMode="Explicit" />
<endpoint address="http://localhost:8060/EmpS" binding="wsDualHttpBinding" bindingConfiguration=""
contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint address="net.tcp://localhost:8888/EmpS" binding="netTcpBinding"
contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint address="net.pipe://localhost/EmpS" binding="netNamedPipeBinding"
contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/EmpS/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
The Code of the Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using SampleEmpServiceLib;
using System.ServiceModel.Description;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(EmpService));
host.Open();
Console.WriteLine("running on endpoints:");
foreach (ServiceEndpoint serviceEndpoint in host.Description.Endpoints)
Console.WriteLine(serviceEndpoint.Address.ToString());
Console.WriteLine("running");
Console.ReadLine();
host.Close();
}
}
}
I can suggest some updates to config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"
policyVersion="Default" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="SampleEmpServiceLib.EmpService">
<clear />
<endpoint binding="basicHttpBinding" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint address="dual" binding="wsDualHttpBinding" bindingConfiguration="" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint binding="netTcpBinding" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint binding="netNamedPipeBinding" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/EMPS" />
<add baseAddress="net.tcp://localhost:8888/EMPS" />
<add baseAddress="net.pipe://localhost/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>

Could not find default endpoint element that references contract

I have self hosted a WCF service from a console application (HOST). I am calling HOST from another console application (PARENT). When I run PARENT, everything works fine like the WCF hosted successfully and instance of service reference is also getting created. The PARENT application is actually a plug-in for another big unmanaged application(BIG A). When I start the PARENT application from BIG A , the console application self hosts the service successfully. However I am getting following error while creating the instance of service.
Could not find default endpoint element that references contract 'CalculatorServiceReference.ICalculatorService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
The configuration files are as follows.
•Configuration file of HOST
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="HybridCalcService.CalculatorService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="Mex" contract="IMetadataExchange"
listenUriMode="Explicit">
</endpoint>
<endpoint address="net.tcp://localhost:8523/CalcService" binding="netTcpBinding"
name="Tcp" contract="HybridCalcService.ICalculatorService" listenUriMode="Explicit">
</endpoint>
<endpoint address="HTTP" binding="basicHttpBinding" bindingConfiguration=""
name="HTTP" contract="HybridCalcService.ICalculatorService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Hybridservice" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
•And the config of PARENT is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="HybridCalcService.CalculatorService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="Mex" contract="IMetadataExchange"
listenUriMode="Explicit">
</endpoint>
<endpoint address="net.tcp://localhost:8523/CalcService" binding="netTcpBinding"
name="Tcp" contract="HybridCalcService.ICalculatorService" listenUriMode="Explicit">
</endpoint>
<endpoint address="HTTP" binding="basicHttpBinding" bindingConfiguration=""
name="HTTP" contract="HybridCalcService.ICalculatorService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Hybridservice" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Can anyone help me in this issue?
I believe that the config info has to be in the config file of the main application. Adding that info to the config of BigA should solve the problem.
This looks pretty similar to what I did for a custom channel. if i remember correctly this would go into HOST, and then you wouldn't need anything in the other configs.

Multiple Base Addresses and Multiple Endpoints in WCF

I'm using two bindings TCP and HTTP. I want to give mex data on both bindings.
What I want is that the mexHttpBinding only exposes the HTTP services while the mexTcpBinding exposes TCP services only. Or is this possible that I access stats service only from HTTP binding and the eventLogging service from TCP?
For Example:
For TCP I should only have
net.tcp://localhost:9001/ABC/mex
net.tcp://localhost:9001/ABC/eventLogging
For HTTP
http://localhost:9002/ABC/stats
http://localhost:9002/ABC/mex
When I connect with any of the base address (using the WCF Test Client) I'm able to access all the services? Like when I connect with net.tcp://localhost:9001/ABC I'm able to use the services which are offered on the HTTP binding. Why is that so?
<system.serviceModel>
<services>
<service behaviorConfiguration="ABCServiceBehavior" name="ABC.Data.DataServiceWCF">
<endpoint address="eventLogging" binding="netTcpBinding" contract="ABC.Campaign.IEventLoggingService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="stats" binding="basicHttpBinding" contract="ABC.Data.IStatsService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9001/ABC" />
<add baseAddress="http://localhost:9002/ABC" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ABCServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I want to give mex data on both
bindings. What I want is that the
mexHttpBinding only exposes the HTTP
services while the mexTcpBinding
exposes TCP services only. Or is this
possible that I access stats service
only from HTTP binding and the
eventLogging service from TCP?
Well, in this case, you need to have two separate, distinct services - one that exposes eventLogging only, and another one that exposes stats only.
When you have two separate services, you can expose one over HTTP and its mex will only show those methods, and the other over TCP/IP and expose its methods.
<services>
<service name="ABC.Data.DataServiceWCFEventlogging"
behaviorConfiguration="ABCServiceBehavior" >
<endpoint address="eventLogging"
binding="netTcpBinding"
contract="ABC.Campaign.IEventLoggingService" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9001/ABC" />
</baseAddresses>
</host>
</service>
<service name="ABC.Data.DataServiceWCFStats"
behaviorConfiguration="ABCServiceBehavior" >
<endpoint address="stats"
binding="basicHttpBinding"
contract="ABC.Data.IStatsService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9002/ABC" />
</baseAddresses>
</host>
</service>
</services>
If you have both methods on the same service, there is no way to expose only parts of it over http and another part over tcp/ip.

Categories