1

I am writing WCF Service - Client. The service is getting the endpoint url as arg, This is Windows Form Application.
The Service impl is:

BaseAddress = new Uri(args[0]);
using (ServiceHost host = new ServiceHost(typeof(DriverService), BaseAddress))
{
   ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
   smb.HttpGetEnabled = true;
   smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
   host.Description.Behaviors.Add(smb);
 //host.AddServiceEndpoint(typeof(DriverService), new BasicHttpBinding(), BaseAddress);
   host.Open();

After host.Open() i get the error, When i wrote same wcf code on another solution it worked just fine, i had the client and service. now i just need to open the service when wait until the client connects.

From what I understand, this is Service and i give it address, then it listens on the given address and exposing the methods on the interface to different clients.

Error:

Service 'DriverHost.DriverService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.  

Code of interface and class:

[ServiceContract]
public interface IDriverService
{
    [OperationContract]
    string WhoAmI();
}

public class DriverService : IDriverService
{
    public string WhoAmI()
    {
        return string.Format("Im on port !");
    }
}
ilansch
  • 4,784
  • 7
  • 47
  • 96
  • Do you have bindings in you app.config – Dave Hogan Mar 18 '13 at 10:28
  • i have nothing in my app.config, but in a sample i have made, i didnt write any binding also – ilansch Mar 18 '13 at 10:31
  • this might be duplicate http://stackoverflow.com/questions/2807525/wcf-self-host-service-endpoints-in-c-sharp?rq=1 ...examine answers... – ilansch Mar 18 '13 at 10:40
  • I am assuming the error you get is on the client side. Do you have the Server running before starting the client application? – Rajesh Mar 18 '13 at 17:38

1 Answers1

2

since there is different between .net 4.5 and 3.5 i understand there is no default Endpoints.
So needed to declare:

BaseAddress = new Uri(args[0]);
using (ServiceHost host = new ServiceHost(typeof(Namespace.Classname), BaseAddress))
{
  ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
  smb.HttpGetEnabled = true;
  smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
  host.Description.Behaviors.Add(smb);
  host.AddServiceEndpoint(typeof(Namespace.IInterface), new BasicHttpBinding(), args[0]);
  host.Open();

Meaning - add the .AddServiceEndpoint(..) and make sure that on ServiceHost() write the class, and on AddServiceEndpoint enter the Interface.

ilansch
  • 4,784
  • 7
  • 47
  • 96