6
namespace helloserviceSelfHostingDemo
{
    [ServiceContract]
    interface IhelloService
    {
        [OperationContract]
        string sayhello(string name);
    }

public class HelloService : IhelloService
{

    public string sayhello(string name)
    {
        return "hello " + name;
    }
}
class Program
{
    static void Main(string[] args)
    {
        ServiceHost host = new ServiceHost(typeof(HelloService));
        BasicHttpBinding bind = new BasicHttpBinding();
        host.AddServiceEndpoint(typeof(IhelloService), bind, "http://8080/myhelloservice");
        host.Open();
        Console.WriteLine("hello service is running");
        Console.ReadKey();
    }
}

}

this code runs well but when i am copies this address in the browser is not getting the service

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3691649
  • 61
  • 1
  • 2

3 Answers3

3

You need your mex binding, like this:

string mexAddress = "http://localhost:8000/servicemodelsamples/service/mex";
MetadataExchangeClient mexClient = new MetadataExchangeClient("MyMexEndpoint");
mexClient.ResolveMetadataReferences = true;
MetadataSet mdSet = mexClient.GetMetadata(new EndpointAddress(mexAddress));

Without the Mex, there's no meta data to publish when one navigates to the URL.

Brian
  • 3,653
  • 1
  • 22
  • 33
  • 1
    And also ensure when it goes to production that the binding is removed for security purposes. –  Jun 03 '14 at 07:08
2

You need to expose the meta data information.

Uri baseAddress = new Uri("http://localhost:8080/hello");

using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
{
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    host.Description.Behaviors.Add(smb);
    host.Open();

    Console.WriteLine("The service is ready at {0}", baseAddress);
    Console.WriteLine("Press <Enter> to stop the service.");
    Console.ReadLine();
    host.Close();
}

Source : http://msdn.microsoft.com/en-us/library/ms731758(v=vs.110).aspx

Anuraj
  • 18,859
  • 7
  • 53
  • 79
0

Add below endpoint in your WCF service web.config file

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
Rachit Patel
  • 854
  • 5
  • 12