0

I have WCF service with wsDualHttpBinding. How to host it in managed application?

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

using (ServiceHost host = new ServiceHost(typeof(FileServer), baseAddress))
{
    host.Open();
    Console.ReadLine();
    host.Close();
}
oleksii
  • 35,458
  • 16
  • 93
  • 163
  • 1
    What error do you get? If this is permissions issue, make sure you run it with Administrator permissions. If you debug your app from Visual Studio you have to specifically run the IDE as Administrator. – oleksii Apr 07 '13 at 18:42
  • Contract requires duplex but binding 'basicHttpBinding' doesn't support it –  Apr 07 '13 at 18:46
  • 2
    There seems to be [2630 search results](https://www.google.co.uk/search?q=Contract+requires+duplex+but+binding+'basicHttpBinding'+doesn't+support+it) for this error, have you looked at those? – oleksii Apr 07 '13 at 18:48
  • I did. The problem is how to set the Binding for the host. –  Apr 07 '13 at 18:49
  • [This](http://msdn.microsoft.com/en-us/library/ms585836.aspx) shall do it. – oleksii Apr 07 '13 at 18:51
  • You have alot of data missing.. Have you followed http://msdn.microsoft.com/en-us/library/ms731758.aspx ? – ilansch Apr 07 '13 at 19:19
  • as @oleksii mentioned, you are missing the Metadata endpoint behaviour you must add it to your ServiceHost. otherwise the endpoint service will not know how to listen to client calls – ilansch Apr 07 '13 at 19:45
  • @ilansch I fixed that. I'll publish my solution tomorrow, because users with reputation less than 10 can't answer their own question for 8 hours after asking –  Apr 07 '13 at 20:00
  • @ilansch let' vote OP's question up, so he can post an answer. – oleksii Apr 07 '13 at 20:06

1 Answers1

0

The solution was to add endpoint to my service:

Uri baseAddress = new Uri("http://localhost:51160");
WSDualHttpBinding binding = new WSDualHttpBinding();
using (ServiceHost host = new ServiceHost(typeof(FileServer), baseAddress))
{
    host.AddServiceEndpoint(typeof(IFileServer), binding, "http://localhost:51160/FileServer");

    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    host.Description.Behaviors.Add(smb);

    host.Open();
    Console.ReadLine();
    host.Close();
}

And the same thing on server side (in config)

<services>
  <service name="AK3_Server.FileServer" behaviorConfiguration="FileServerBehavior">
    <endpoint address="http://localhost:51160/FileServer" binding="wsDualHttpBinding"
      bindingConfiguration="" contract="AK3_Server.IFileServer" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="FileServerBehavior">          
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>          
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
  • Hi man, you do the same thing duplicated, you only need to config it using config file or via C# code.. not from both places.. put whats in app.config in comment it will still work – ilansch Apr 08 '13 at 15:23