1

I created a wcf application. I didn't change anything. Used the Service1.GetData(int). It works fine. I can hit the wsdl in a browser and everything. Then I created a custom service host factory that simply returns a new service host and the service never comes up. I can no longer get to the wsdl in a browser. I tried adding a Custom ServiceHost so I could do a little debugging and it appears that there are no endpoints being found (even when explicitly calling AddDefaultEndpoints(). This is true even when I explicitly add the endpoint to the web.config.

Does anyone have any ideas as to what the issue could be?

If anyone cares to take a look I put the code on github: https://github.com/devlife/Sandbox/tree/master/WcfService1

devlife
  • 15,275
  • 27
  • 77
  • 131
  • Thanks for putting the code up, I'll have a look. – peter Dec 19 '11 at 20:32
  • When you browse to your wsdl and it doesn't work, what is the actual result you get? Do you get a 404 or a 500 for instance, or do you just get nothing? Fiddler will tell you if you browser doesn't. – peter Dec 22 '11 at 20:34

2 Answers2

0

Here is how I have defined a CustomHost in a project I am working on,

<%@ ServiceHost Language="C#" Debug="true" Service="Servicename.Servicename" CodeBehind="Service1.svc.cs" Factory="WcfService1.CustomServiceHostFactory"%>

And this,

public class CustomServiceHostFactory : ServiceHostFactory
{
    public CustomServiceHostFactory()
    {

    }

    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        return new CustomServiceHost(serviceType, baseAddresses);
    }
}

public class CustomServiceHost : ServiceHost
{
    public CustomServiceHost()
    {
    }

    public CustomServiceHost(Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
    {
    }

    protected override void OnOpening()
    {
        base.OnOpening();
    }

    protected override void OnClosing()
    {
        base.OnClosing();
    }

    protected override void ApplyConfiguration()
    {
        base.ApplyConfiguration();
    }
}

Note that the CustomServiceHost looks bare, but that is because my solution has a lot of logging and configuration in this CustomServiceHost that I removed and is not appropriate.

The other difference I can see also is that my CustomServiceHost does not add the endpoint. The endpoint is defined in the config file like this,

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Servicename.Servicename" behaviorConfiguration="ServiceBehavior">
    <endpoint address="http://*******.svc" binding="wsHttpBinding" contract="Namespace.IContract" bindingConfiguration="BindingConfig">
    </endpoint>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="BindingConfig" maxReceivedMessageSize="9291456">
      <security mode="None">
      </security>
      <readerQuotas maxArrayLength="6291456" />
    </binding>
  </wsHttpBinding>
</bindings>

peter
  • 13,009
  • 22
  • 82
  • 142
  • Sorry about that. I was going back and forth between using the Factory and not using it. When I don't use the factory I can get to http://localhost/WcfService1/Service1.svc?wsdl. However, when I use the factory I can't get to the wsdl. – devlife Dec 20 '11 at 14:55
  • OK, so what happens when you have nothing in the ApplyConfiguration code, and put your configuration in the web.config file? More like what I have shown above. – peter Dec 20 '11 at 19:44
  • When I comment out the ApplyConfiguration method and put in the config you specified then I cannot get to the wsdl. Even if I add a mex endpoint. It says that the metadata is turned off. However, if remove the custom service host factory then it works as expected. I updated the code in github if you want to take a look. I'm very confused by this. – devlife Dec 22 '11 at 15:40
  • I'm confused. I downloaded your new version and it worked fine for me as it was. When you say the wsdl do you mean this address http://localhost:39506/Service1.svc?wsdl and it says 'you have created a service'. That is what I am getting. – peter Dec 22 '11 at 20:18
  • I can see a couple of differences, you are using IIS to debug your service, based on your project settings. Try to use the 'visual studio development server' and see if that works? Also you could try IIS express. What about if you browse to your wsdl with different browsers too. Also you could use fiddler to look at what happens when you browse to the svc, it will tell you what the response from the web server is. Let us know what you get. – peter Dec 22 '11 at 20:25
0

Why are you using ServiceHostFactory? are you going to use AppFabric/IIS? or self hosted services?

I think you need to add a MEX endpoint.

    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
Guy
  • 336
  • 4
  • 18
  • I don't think that has anything to do with this issue. The only reason I'm hitting the wsdl is to start the service. The problem I'm having is that no endpoints are being found. Debug inside CustomServiceHost to see what I'm talking about. – devlife Dec 20 '11 at 14:55