I created a WCF service and Hosted it through console. but when I created another Web Application and tried to add it service reference its give error
Metadata contains a reference that
cannot be resolved:
‘net.tcp://192.0.0.0:9100/ConsoleApplication3/Communicator.svc/mextcp’.
Could not connect to
net.tcp://192.0.0.0:9100/ConsoleApplication3/Communicator.svc/mextcp.
The connection attempt lasted for a
time span of 00:00:00.9843750. TCP
error code 10061: No connection could
be made because the target machine
actively refused it 192.0.0.0:9100.
No connection could be made because
the target machine actively refused it
192.0.0.0:9100 If the service is defined in the current solution, try
building the solution and adding the
service reference again.
Here is code:
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
try
{
using (ServiceHost host = new ServiceHost(typeof(Communicator)))
{
host.Open();
Console.WriteLine("Press <Enter> to terminate the Host application.");
Console.ReadLine();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
[ServiceContract]
public interface ICommunicator
{
[OperationContract]
string SayHello();
}
public class Communicator : ICommunicator
{
public string SayHello()
{
return "I am here";
}
}
And here is the configuration:
<configuration>
<system.serviceModel>
<services>
<service name="ConsoleApplication3.Communicator" behaviorConfiguration="CommunicatorBehavior">
<!-- Service Endpoints -->
<endpoint address="ConsoleApplication3" binding="netTcpBinding"
contract="ConsoleApplication3.ICommunicator"/>
<!-- This Endpoint is used for genertaing the proxy for the client -->
<!-- To avoid disclosing metadata information, set the value below to false and
remove the metadata endpoint above before deployment -->
<endpoint address="mex" contract="IMetadataExchange" binding="mexTcpBinding" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9100/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CommunicatorBehavior">
<serviceMetadata httpGetEnabled="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I think you got a wrong address to try and get at your service.
You have hosted a service yourself in a console app, with
netTcpBinding, and you’ve defined a base address ofnet.tcp://localhost:9100/, and the MEx endpoint is atnet.tcp://localhost:9100/mex.So you need to use either the base address
or the MEX address
when trying to connect to the service.
I don’t know how you came up with this address (
net.tcp://192.0.0.0:9100/ConsoleApplication3/Communicator.svc/mextcp) that you seem to try to connect to – but this address is not valid. First of all – there’s no *.svc file to be used when self-hosting anetTcpBindingwebservice, and I don’t know where you got this/mextcpaddress from…..Update: I took your code, created a new console app with the interface and service implementation and your service config, and it works just fine on my machine:
I did get a warning from Windows Firewall when I tried to launch the console app from within Visual Studio about allowing access – which I did allow.