Correct implementation of nservice bus and wcf

nservicebus

(Alfonso) #1

HI, I’m implementing nservicebus in my wcf services, I’m not clear about it’s responsability or use, I read the documentation and examples but it is not clear to me how the correct integration is bone or the wcf layer is an extra layer?

Example Implementation

public static class Program
{
static void Main()
{
//Client UI
var host = new TestServiceHost();
host.AddServiceHostNetTcp(typeof(ClientService));

    //NServicebus host
    var endpoint = AsyncMain().GetAwaiter().GetResult();
    Application.Run(host);
}

public static async Task<IEndpointInstance> AsyncMain()
{
    var endpointConfiguration = new EndpointConfiguration("Test.NServiceBus.Host");
    endpointConfiguration.SendOnly();
    endpointConfiguration.UseSerialization<JsonSerializer>();
    endpointConfiguration.UsePersistence<InMemoryPersistence>();

    var transport = endpointConfiguration.UseTransport<LearningTransport>();
    transport.NoPayloadSizeRestriction();
    transport.StorageDirectory(@"c:\StorageDirectory");

    endpointConfiguration.SendFailedMessagesTo("error");
    endpointConfiguration.AuditProcessedMessagesTo("audit");

    var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
    //Instance of the endpoint to the wcf service
    ClientService.endpointInstance = endpoint;
    return endpoint;
}

}

public class ClientService : IClientService
{
public static IEndpointInstance endpointInstance;

public BaseResponse GeClient(GetClienteRequest request)
{
    var clienteResponse = await endpoint.Request<GetClienteResponse>(new ClienteRequest { IdClient = request.IdClient });
    return clienteResponse;
}

public BaseResponse CreateClient(CreateClientRequest request)
{
    try
    {
        var domain = new Cliente
        {
            Id = Guid.NewGuid(),
            Name = request.Name,
            LastName = request.LastName
        };

        repository.Save(domain);
        endpointInstance.Publish(new CreateAccountClient(domain.Id));
        response.SetOk();
    }
    catch (BoundedContextException ar)
    {
        response.SetError(ar.Message);
    }
    return response;
}

}


(Daniel Marbach) #2

Hi alfonso

Have you seen our WCF extension?

https://docs.particular.net/nservicebus/wcf/

Reagrds
Daniel