Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF service self host url not getting wsdl document

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

like image 725
user3691649 Avatar asked Jun 03 '14 06:06

user3691649


2 Answers

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.

like image 194
Brian Avatar answered Nov 02 '22 11:11

Brian


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

like image 2
Anuraj Avatar answered Nov 02 '22 12:11

Anuraj