WCF service self host url not getting wsdl document
Asked Answered
R

3

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

Reactive answered 3/6, 2014 at 6:30 Comment(2)
8080/myhelloservice.svc?Jabber
You should really configure the WCF service using the application configuration.Vaughan
M
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.

Mccown answered 3/6, 2014 at 6:53 Comment(1)
And also ensure when it goes to production that the binding is removed for security purposes.Foreleg
G
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

Grearson answered 3/6, 2014 at 7:13 Comment(0)
D
0

Add below endpoint in your WCF service web.config file

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
Diesel answered 3/6, 2014 at 8:44 Comment(1)
There is no web.config for a self hosted WCF service. You mean app.config.Vaughan

© 2022 - 2024 — McMap. All rights reserved.