Skip to content

Initialization

HX-Rd edited this page Mar 9, 2018 · 2 revisions

Initialization

Solid.AspNetCore.Extensions.Wcf is designed to work with the Startup class and IServiceCollection.

Basic initialization

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // MyWcfService is an implementation of an interface that is defined
        // as a service contract using the ServiceContractAttribute in System.ServiceModel
        services.AddWcfServiceWithMetadata<MyWcfService>();
    }

    public void Configure(IApplicationBuilder builder)
    {
        // IMyWcfServiceContract is the service contract that MyWcfService implements. 
        // The Wcf service will be hosted as /service using the BasicHttpBinding
        builder.UseWcfService<MyWcfService, IMyWcfServiceContract>("/service");
    }
}

Other initialization

There are more options that can be used during startup.

Change the default binding

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // MyWcfService is an implementation of an interface that is defined 
        // as a service contract using the ServiceContractAttribute in System.ServiceModel
        services
            .AddWcfServiceWithMetadata<MyWcfService>()
            .AddDefaultBinding<WSHttpBinding>();
    }

    public void Configure(IApplicationBuilder builder)
    {
        // IMyWcfServiceContract is the service contract that MyWcfService implements. 
        // The Wcf service will be hosted as /service using the WSHttpBinding
        builder.UseWcfService<MyWcfService, IMyWcfServiceContract>("/service");
    }
}

Multiple bindings

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // MyWcfService is an implementation of an interface that is defined 
        // as a service contract using the ServiceContractAttribute in System.ServiceModel
        services.AddWcfServiceWithMetadata<MyWcfService>();
    }

    public void Configure(IApplicationBuilder builder)
    {
        // IMyWcfServiceContract is the service contract that MyWcfService implements. 
        builder.UseWcfService<MyWcfService>("/service", b =>
        {    
            // The Wcf service will be hosted as /service using the BasicHttpBinding
            b.AddServiceEndpoint<IMyWcfServiceContract>();
            // The Wcf service will be hosted as /service/ws using the WSHttpBinding
            b.AddServiceEndpoint<IMyWcfServiceContract>(new WSHttpBinding(), "ws");
        });
    }
}