I am getting an issue to open the WCF service in browser with localhost:8733. it says that This site can’t be reached
localhost refused to connect.
Search Google for localhost 8733
Home Search Flight
ERR_CONNECTION_REFUSED
Below is the configuration file is used in the console application which is the hosting the application
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mex1">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="HelloIndigo.HelloIndigo" behaviorConfiguration="mex1">
<endpoint address="HelloIndigo" binding="basicHttpBinding" contract="HelloIndigo.IHelloIndigo">
</endpoint>
<endpoint address="HelloIndigo" binding="netTcpBinding" contract="HelloIndigo.IHelloIndigo"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/" />
<add baseAddress="net.tcp://localhost:9000"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
in the Host console application i am writing the below code
ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigo));
host.Open();
Console.WriteLine("Host is opened at " + DateTime.Now.ToString())
Next day morning in the office, when I opened the project the same issue came up - "This site can’t be reached". As per my previous experience with this issue, I changed a port number and it started working. But this time, it didn't help. Then I tried another way (see screenshots below).
A problem:
Solution:
This is the other way that works for me . I hope this will help who faces the same issue.
Related
I am new to WCF and trying to understand Mex endpoints. I have created a testservice. Its working fine and I am able to view WSDL output from URL= "http://myweb.com:8000/testservice" as well using "URL" or "URL?wsdl".
However, I am getting 400 Bad request while browsing "URL/mex" in browser. I set httpGetEnabled="false" and then I am also able generate proxy class using svcutil as well.
Could you please advise why I am not able to veiw mex endpoint output in web browser. Below is the config file:
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="HelloTest.testservice" behaviorConfiguration="serviceBehaviour">
<endpoint binding="basicHttpBinding" contract="HelloTest.Itestservice" address="HelloTest">
</endpoint>
<endpoint binding="mexHttpBinding" contract="IMetadataExchange" address="mex">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://myweb.com:8000/testservice"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehaviour">
<serviceMetadata httpGetEnabled="true"></serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I have a WCF service that I tested by copying its interfaces to a sample client project.
Now I want to work properly by adding a service reference.
The service is hosted in windows hosting (using installUtil).
The service has 2 projects - externals (interfaces + datacontracts) and internals (implementations).
For some reason it didn't have an app.config so I added one manually:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="ExecutionService" behaviorConfiguration="Default">
<endpoint name="TCPEndpoint" address="" binding ="netTcpBinding" contract="Externals.IExecutionService"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:3040/ExecutionService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Trying to add a service reference from my sample client causes the following error:
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:3040/ExecutionService/Externals.IExecutionService'.
There was no endpoint listening at net.tcp://localhost:3040/ExecutionService/Externals.IExecutionService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I saw here that there's no need in app.config.
I'm a bit confused and I'm a beginner with WCF.
How can a nice WPF app reference my service? I want the service to be windows hosted and I don't want to drag dlls with me.
Edit
I added a metadata endpoint and my appconfig now looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="ExecutionService" behaviorConfiguration="Default">
<endpoint name="TCPEndpoint"
address=""
binding ="netTcpBinding"
contract="Externals.IExecutionService"/>
<endpoint address="mex"
binding="maxHttpBinding"
contract="Externals.IExecutionService"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:3040/ExecutionService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I tried adding a service reference by using net.tcp://localhost:3040/ExecutionService, net.tcp://localhost:3040/ExecutionService/Externals and net.tcp://localhost:3040/ExecutionService/Externals/IExecutionService and I'm still getting the same error.
You need to do:
maxHttpBinding -> mexTcpBinding - you cannot use mexHttpBinding on net.tcp endpoint (and it's mex not max)
the contract for mex endpoint must be IMetadataExchange - as you want to have service metadata available through this endpoint
httpGetEnabled="false" as there will be no http endpoint to get metadata from
When I was testing the solution in a simple console host I needed to change name in <service> tag to Externals.ExecutionService (but this depends on how you instantiate the service)
Then your service reference will be available at: net.tcp://localhost:3040/ExecutionService/mex
as base address is net.tcp://localhost:3040/ExecutionService and the relative address for the mex endpoint is set to mex
Final app.config is below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="Externals.ExecutionService" behaviorConfiguration="Default">
<endpoint name="TCPEndpoint"
address=""
binding ="netTcpBinding"
contract="Externals.IExecutionService"/>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:3040/ExecutionService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
For a quick test if the configuration is correct I used console host app as a service host.
Program.cs:
using System;
using System.ServiceModel;
namespace Externals
{
class Program
{
static void Main(string[] args)
{
var sh=new ServiceHost(typeof(ExecutionService));
sh.Open();
Console.WriteLine("Service running press any key to terminate...");
Console.ReadKey();
sh.Close();
}
}
}
Run the console app and try to add service reference to your project through net.tcp://localhost:3040/ExecutionService/mex.
At first glance, you've forgotten Metadata Endpoint
Change this:
<endpoint address="mex"
binding="maxHttpBinding"
contract="Externals.IExecutionService"/>
To:
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
Notice it's not maxHttpBinding but mexTcpBinding, you had typo as well there.
I am trying hard to develop a duplex wcf service to be consumed by silverlight clients. Now for adventure sake, I decided to use nettcpbinding. I understand that the concept of PolicyServer to be running on port 943 is obselete now and it should be served from root of the service.
given Below is config section for the service
<behaviors>
<serviceBehaviors>
<behavior name="WcfServer.WcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="CrossDomainServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WcfServer.WcfServiceBehavior"
name="WcfServer.MainService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPBinding" contract="WCFWebFrontCommunication.IMainService">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="CrossDomainServiceBehavior" contract="WCFWebFrontCommunication.IClientAccessPolicy" />
<host>
<baseAddresses>
<!--<add baseAddress= "http://192.168.0.101:943/WcfServer/MainService" />-->
<!--<add baseAddress= "http://localhost:943/WcfServer/MainService" />-->
<add baseAddress= "net.tcp://localhost:4502/WcfServer/MainService" />
<add baseAddress="http://localhost:4502"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
now at runtime I get an exception HTTP could not register URL http://+:4502/ because TCP port 4502 is being used by another application. when Open Method is called.
Am I doing something silly here .., although http exception was there with basicHttpBinding as well
As Troubleshooting:
checked for open port using Netstat -aon
There were some post regarding HTTP configuration followed them nothing happened
Thanks for reading.
You're trying to host a clientaccesspolicy.xml file over HTTP, and use net.tcp on the same port number, that's not going to work. While both of these protocols build on TCP/IP, they are incompatible.
As far as I understand (see also this article), port 943 is still used for this type of thing.
I have started learning WCF and have created a few test http services successfully. Now, i was trying to create a self-hosted WCF service using net.pipe binding. Below is the configuration file for the service:-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MEX" name="InProcService.MyService">
<endpoint address="MyService"
binding="netNamedPipeBinding" bindingConfiguration="" contract="InProcService.IMyService" />
<endpoint address="Mex" binding="mexNamedPipeBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/InProcService/" />
<add baseAddress="http://localhost:8001/InProcService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MEX" >
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Now in my host application, I am starting the service using:-
ServiceHost host = new ServiceHost(typeof(MyService));
host.Open();
Console.WriteLine("Service started");
host.Close();
The service starts correctly when this code is executed.
Now, when in my client application, I try to add the service reference to this running service, it is not able to find it. Is there something which I am not doing or doing incorrectly?
I would appreciate any help I can get on this.
Cheers,
Abhi.
The service is opened and closed after that. By the time you start the client the server is already closed. So Console.ReadKey() is required is requied before close.
using ASP.net, C#, IIS, jQuery
I have a wcf service running in iis on port 2515.
the demo i created for this project works fine and i can utilize the service.
I have another project running on port 2971.
I want this project to consume the wcf service via javascript but am getting a "method not allowed error".
Is this a cross-site scripting issue? I'm thinkin no since both projects are on the same domain but at different port numbers.
any help would be much appreciated.
<serviceBehaviors>
<behavior name = "MetadataBehavior">
<serviceMetadata httpGetEnabled = "true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SandwichServices.CostServiceAspNetAjaxBehavior" >
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="SandwichServices.CostService" behaviorConfiguration="MetadataBehavior">
<endpoint address="" behaviorConfiguration="SandwichServices.CostServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="SandwichServices.CostService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:2152/"/>
</baseAddresses>
If you're using XHR, the port is taken into account in the same-origin policy. You can't do requests across different ports - think of it as a part of the domain name.