Reputation: 4878
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 !");
}
}
Upvotes: 1
Views: 540
Reputation: 4878
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.
Upvotes: 2