Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here i'am creating a Hello wcf service which returns a string and the code is following


code in app.config file

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="WcfDemo.HelloService" behaviorConfiguration="mexBehaviour">
        <endpoint address="HelloService" binding="basicHttpBinding" contract="WcfDemo.IHelloService"></endpoint>
        <endpoint address="HelloService" binding="netTcpBinding" contract="WcfDemo.IHelloService"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
            <add baseAddress="net.tcp://localhost:8010/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>



and code in wcf service is

C#
namespace WcfDemo
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HelloService" in code, svc and config file together.
    public class HelloService : IHelloService
    {

        public string Hello(string Name)
        {
           return "Hello " + Name;
        }
    }
}



Code in automatically generated classfile is


C#
namespace WcfDemo
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IHelloService" in both code and config file together.
    [ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        string Hello(string Name);
    }
}



i have hosted this wcf service in console application and the code is

C#
namespace HelloServicehost
{
    class Program
    {
        static void Main()
        {
            using (ServiceHost host = new ServiceHost(typeof(WcfDemo.HelloService)))
            {
                host.Open();
                Console.WriteLine("Service Started at @ " + DateTime.Now.ToString());
                Console.ReadLine();
            }
        }
    }
}



Here console application is hosted in consoleapplication successfully but when i trying to open http://localhost:8080/ iam not getting the wsdl document.

THE ERROR IAM GETTING IS
(Google Chrome's connection attempt to localhost was rejected. The website may be down, or your network may not be properly configured). HOW TO SOLVE IT?
actually iam learner of wcf services so i could not find the whether the error is thrown from the browser or from the application. some one help me thanks in advance.
Posted
Updated 26-Nov-14 0:35am
v4
Comments
Mehdi Gholam 17-Nov-14 7:52am    
What is the error?
raxhemanth 17-Nov-14 8:25am    
Webpage not available error as specified above

1 solution

I might be late in answering,but the thing with 'using' is that its closing the connection just as soon as it opens
You can use something like

ServiceHost host = new ServiceHost(typeof(CalcService.CalcService));

host.Open();
 
Share this answer
 
v2
Comments
[no name] 11-Oct-15 11:02am    
"I might be late in answering": yes you are. Nevertheless better late than never ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900