nservicebus wcf integration 101
DESCRIPTION
NServicebus WCF Integration 101TRANSCRIPT
![Page 1: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/1.jpg)
NServiceBus and WCF Integration101
October 10, 2014By Rich Helton
![Page 2: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/2.jpg)
Why NServiceBus?
NServiceBus (NSB) is the most popular ESB for the C# platform in existence. It is decentralized and has many tools to assist in deployment. Many people may wonder the need to use an ESB? It is to manage services for any applications not performing in the website.
![Page 3: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/3.jpg)
Source code
My test source code can be found athttps://github.com/richhelton
Particular samples and souce code can be found at https://github.com/Particular
![Page 4: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/4.jpg)
For those that don't use ESBs....
You may see many websites that say “Don't refresh this page” for instance as they are website only centric that may not consider an ESB. You may also talk to some of their staff to know that they do not acknowledge that server and network errors can occur. For those who want to monitor their services, transactions, messages, and give your website the ability to refresh a page after you enter a credit card, we have NSB.
![Page 5: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/5.jpg)
What is a Service-Oriented Architecture
SOA is a combination of design patterns, usually implemented through frameworks.SOA combines distinct services that are communicated through messages to cooperate as a single end-to-end business system. A service could be considered a Windows service, or a distinct unit of work, such as a mainframe job.
![Page 6: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/6.jpg)
SOA Visual
![Page 7: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/7.jpg)
More SOA Advantages
By using services, we may start/stop services based on performance. We may get running totals on the number of successful and error messages.
![Page 8: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/8.jpg)
What is a Enterprise Service Bus (ESB)?
ESB is a software architecture design model in which a common bus is shared across a framework to allow common agreed upon communication between different endpoints or services.
![Page 9: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/9.jpg)
An ESB Visual
![Page 10: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/10.jpg)
Software Quality
Software Quality are cross-cutting features of the software, that normally defines the technical requirements of the software itself.These qualities are usually security, re-use, maintainability, reliability, efficiency, and other characteristics that make one want to use the framework. Notice that NSB match these qualities one-to-one.
![Page 11: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/11.jpg)
SOA and ESBs to the rescue
In the Microsoft world, when discussing a framework that implements Service Oriented Architecture (SOA), one may think of the Windows Communication Foundation (WCF) web services.
![Page 12: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/12.jpg)
SOA and ESBs to the rescue
In the Microsoft world, when discussing a framework that implements Service Oriented Architecture (SOA), one may think of the Windows Communication Foundation (WCF) web services.
![Page 13: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/13.jpg)
Benefits for NSB
Separate business logic between services. High availability of services. Highly configurable. Message durability in guaranteed delivery. Viewing and monitoring messages and services give an end-to-end viewpoint. Retries for sending of messages. Message workflows in the form of Sagas. Heartbeats to give real-time status. Easy encryption of messages and data. NSB Hosting and installation tools.
![Page 14: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/14.jpg)
Some Basics
October 10, 2014By Rich Helton
![Page 15: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/15.jpg)
The Message
NSB is built to send messages on a queue using a variety message queues and techniques, along to various configurations for almost any type of Service. First we start with messages. IMessage – is a basic message interface. IEvent – used mostly for publish-subscribe, and is a type of IMessage. ICommand – used mostly for request-response, and is a type of IMessage.
![Page 16: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/16.jpg)
Some simple Message code
![Page 17: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/17.jpg)
The Bus
NSB is built on configuring its ESB bus called IBus, and I can be configured for multiple queue and persistence, endpoint, services and message scenarios. A very basic configure.
![Page 18: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/18.jpg)
The Message handler
NSB sends messages through the Send() or Publish() methods, but it needs a message handler to be listening on on the message queue to process the message. A message handler will listen on an endpoint looking for a particular message. The endpoints and message that it is listening for is defined in the App.config, and in the message handler function.
![Page 19: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/19.jpg)
A simple Message handler
![Page 20: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/20.jpg)
Additional Tools
October 10, 2014By Rich Helton
![Page 21: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/21.jpg)
Additional Tools for NSB
Service Matrix is a graphical interface extension in Visual Studio for rapid development. Service Pulse is a production monitoring tool for heartbeats and messages. Service Insight provides deep insight into endpoints, messages and services.
![Page 22: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/22.jpg)
ServiceMatrix
Service Matrix is a graphical interface extension in Visual Studio for rapid development. It will generate code from models.
![Page 23: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/23.jpg)
ServiceMatrixSoultion Builder
![Page 24: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/24.jpg)
ServicePulse
Getting heartbeats and custom messages for Production. It is installed as a service that is connected through a URL http://localhost:9090/#/dashboard
![Page 25: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/25.jpg)
ServiceInsight
ServiceInsight provides a deep insight into messages, endpoints and services as they run, to include a graphical representation.
![Page 26: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/26.jpg)
ServiceInsight Messages
ServiceInsight provides detailed message views.
![Page 27: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/27.jpg)
Message Models
Sept 25, 2014By Rich Helton
![Page 28: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/28.jpg)
Message Features
NSB supports many message models such as request-response and publish-subscribe. Messages do not have to be only messages for the NSB Bus, but NSB integrates into databases and web services as well for third party integration. NSB can also be used to integrate into File I/O , as well as the Secure File tranfer Protocol.
![Page 29: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/29.jpg)
Publish-subscribe
NSB supports publish-subscribe, where a publisher puts the message on a queue where multiple subscribers may read it off the queue.
![Page 30: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/30.jpg)
Request-response
NSB supports request-response, where a requester sends a message that the replier receives and responds with a different message.
![Page 31: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/31.jpg)
Saga services
NSB supports sagas, the ability to save message state and respond back to the originator with changes. This is saving message state.
![Page 32: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/32.jpg)
Timeout Message
NSB supports timeout messages, the ability to set a timer in seconds, minutes, etc., or time of day to send a special message that a timeout has occurred, and to process the action, such as delete a message, start a job, and more.Here, we schedule a task every minute.
public void Handle(ScheduleATask message){
Console.WriteLine("Scheduling a task to be executed every1 minute");
Schedule.Every(TimeSpan.FromMinutes(1)).Action(() => bus.SendLocal(new ScheduledTaskExecuted()));
}
![Page 33: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/33.jpg)
Message Mutators
NSB supports message mutators, the ability to mutate, or change, messages during runtime as the message is transmitted through different endpoints. This is valuable tool for adding information, such as debugging, or informational, information as it is running.
![Page 34: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/34.jpg)
Message Encryption
NSB supports message encryption, the ability to encrypt pieces or the whole of messages and data. The default encryption used by NSB is AES.
![Page 35: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/35.jpg)
Scaleout
NSB supports scaleout messaging for clustering, this is the ability to have multiple worker services, that are clones of the same codebase, with a single sender, to offload the performance to multiple machines.
![Page 36: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/36.jpg)
Performance Monitoring
NSB supports performance counters integration into the Windows Performance Monitor to get statistics on endpoints, messages and services.
![Page 37: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/37.jpg)
Gateways
NSB supports gateways, which is the ability to send messages through an HTTP/HTTPS tunneling, in scenarios where HTTPS is needed for security and messages need to pass through these protocols to meet firewall requirements.
![Page 38: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/38.jpg)
Databus
NSB supports databus, which is the ability to attach a file to a link, or attachment, with the message, because the file is too large to be enclosed in the message itself.
![Page 39: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/39.jpg)
Sagas, What are they good for?
October 10, 2014By Rich Helton
![Page 40: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/40.jpg)
Saga Features
Sagas can save state of messages into a data store. Sagas can route messages based on message state. Sagas are event driven to be started by messages. Sagas contain timers to execute events on messages, the timer can be a periodic time such as every hour, or to execute at a certain date and time.
![Page 41: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/41.jpg)
Sagas intercept and send messages
Sagas are started by messages, they save data, and send messages. As they intercept messages, they can read and save state based on the message ID to add changes to the message, creating workflow.
![Page 42: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/42.jpg)
Saga visual
![Page 43: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/43.jpg)
Saga saves data
Sagas will save data from a message in the form of the IContainSaga interface.
![Page 44: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/44.jpg)
Saga maps data
Sagas will map the data, depending on the IBus configuration, from/to the message to/from the Saga Data object.
![Page 45: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/45.jpg)
Saga handle messages
Sagas are started by at least one message and handler messages.
![Page 46: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/46.jpg)
Saga data from messages
Sagas can save data, the Data object, associated with a message key to get details on the end-to-end workflow of the message
![Page 47: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/47.jpg)
Saga data from messages
Sagas can retrieve data associated with a message key to get details on the end-to-end workflow of the message
![Page 48: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/48.jpg)
ConfigureHowToFindSags()
Sagas need to know how to lookup messages, the key association, usually from an ID in the message, the ConfigureHowToFindSaga() performs this function.
![Page 49: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/49.jpg)
Timeouts
Sagas can handle timeouts
Set a timer
Catch a timer message
![Page 50: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/50.jpg)
Semi-conclusions
Sagas are very robust and require a class of slides unto themselves.
More on them later.
![Page 51: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/51.jpg)
Persistence Patterns
October 10, 2014By Rich Helton
![Page 52: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/52.jpg)
Persistence Features
NSB supports many methods to queue and persists messages. NSB can save subscription information for publish-subscribe in various models. NSB can save Saga data information into various models. NSB takes care of the mapping of the data objects.
![Page 53: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/53.jpg)
Available Persistent models
![Page 54: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/54.jpg)
Persistence interfaces
In-Memory – items that are persisted in the the memory of the service itself. RavenDB – the default for many items like subscriptions, items are persisted in a local Raven database. MSMQ – the default for messages, items are persisted in the Microsoft Message Queuing. NHibernate – a .NET Hibernate framework to map objects to relational databases, to include SQL Server, MySQL, and many others.
![Page 55: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/55.jpg)
What is persisted?
Timeouts – items that keep track of timeouts. Default is RavenDB. Subscriptions – the information to keep track of the subscriber information in publish-subscribe. Default is RavenDB. Sagas – the information stored for Saga data from messages. Default is RavenDB. Gateway – the information to keep track of gateway messaging. Default is RavenDB. Distributor – the messages that is sent to different workers. Default is MSMQ.
![Page 56: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/56.jpg)
Messages
Messages can also be persisted in different types of queues. By default, NSB sends messages in MSMQ. However, by using NHibernate, SQL queuing could just as easily be used to send messages.
![Page 57: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/57.jpg)
Semi-conclusions
NSB persistent patterns are very robust and require a class of slides unto themselves.
More on them later.
![Page 58: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/58.jpg)
WCF Basics
October 10, 2014By Rich Helton
![Page 59: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/59.jpg)
Feature of WCF
The Windows Communication Foundation (WCF) is a Microsoft framework for establishing communications between endpoints, usually between web services. Communication can happen over HTTP, TCP, IPC, or even MSMQ.
![Page 60: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/60.jpg)
The ABCs of WCF
WCF needs specific information to establish a connection to exchange data:Address – the URL address to establish a connection. Binding – which defines the types of services that provide connections, include security and encoding settings. Contracts – defines the operational, the API functions, and data that will be available from the server to the clients.
![Page 61: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/61.jpg)
Contracts
There are three main types of contracts:Service – defines the overall web service starting point. Operational – defines the available methods from the service. Data – defines the available data, through serialization, that is available from the endpoints, usually in the method types.
![Page 62: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/62.jpg)
Operational Contracts
The [OperationContract] defines the available methods from the service.
![Page 63: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/63.jpg)
Data Contracts
The [DataContract] defines the available data from the service.
![Page 64: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/64.jpg)
The address
The address, or available URL, is defined for the server in its App.config or Web.config.
![Page 65: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/65.jpg)
The binding type
The binding type is defined for the server in its App.config or Web.config.We are using the basic http binding and mex http binding as well to expose the endpoint to the client.
![Page 66: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/66.jpg)
Many binding types
There many binding types in WCF as there are many different transport and message types.
A list can be found at http://msdn.microsoft.com/en-us/library/ms730879(v=vs.110).aspx
![Page 67: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/67.jpg)
SVC Config Editor
We can graphically configure the App.config, or Web.config if IIS app, using the service configuration editor. Opening it in Visual Studio,
![Page 68: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/68.jpg)
SVC Config overview
We can see all the items to graphically configure
![Page 69: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/69.jpg)
Seeing the contract
The client will need import the contracts in the form of a proxy to communicate to the server. One of the forms of importing web service interfaces is the Web Service Definition Language (WSDL).
![Page 70: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/70.jpg)
The WSDL is online
In most cases the WSDL is online, as it defines the interfaces needed for the clients.
![Page 71: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/71.jpg)
Viewing the WSDL
We can see that the WSDL has many of the ABC web service components to connect to the web service server.
![Page 72: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/72.jpg)
Adding the Service Reference
We can add the Service Reference to the client to use the interfaces to communicate to the server.
![Page 73: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/73.jpg)
The Service shows us sample client code
![Page 74: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/74.jpg)
Implementing the client code
![Page 75: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/75.jpg)
Adding Tracing
The WCF Services, be it client or server, can have trace listeners to be added to the application as it runs. Microsoft provides a Service Trace Viewer to view these messages, as the interaction can contain WCF specific pieces. See http://msdn.microsoft.com/en-us/library/ms732023(v=vs.110).aspx
![Page 76: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/76.jpg)
Configure Tracing
We can configure the tracing through the service configuration editor, to store in the App.config.
![Page 77: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/77.jpg)
Viewing Tracing
This will allow us to get information on endpoints, such as the messages.
![Page 78: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/78.jpg)
Hosting WCF
The WCF Server listens for incoming requests from the WCF client. Therefore, it should be available when a client needs to connect. The WCF Service can be running as a Windows Service. In an IIS application. Self-Hosted as a .NET application, usually with a
command window. Or as a Windows Process Activation Service
(WAS).
![Page 79: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/79.jpg)
WCF Integration
Sept 25, 2014By Rich Helton
![Page 80: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/80.jpg)
NSB support of WCF
NSB supports WCF integration. The benefits of using NSB with WCF are: NSB simplifies the coding of contracts of WCF, as
well as hosting. This saves on development time. A web service endpoint can be handled as any
other NSB endpoint. This allows all the other benefits of NSB in WCF,
such as message encryption and retries.
![Page 81: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/81.jpg)
NSB-WCF messages
Messages in NSB are defined with the IMessage interface. This can be done instead of a data contract in WCF.
public class PaymentMessage : IMessage{
public Guid EventId { get; set; }public PaymentReq paymentReq { get; set; }
}
![Page 82: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/82.jpg)
NSB-WCF operations
Instead of using operations in WCF, NSB uses message handlers to receive a defined message and process it, and in many cases send back a message response.
![Page 83: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/83.jpg)
NSB-WCF-Saga
Becuase NSB supports Saga workflows, retries, timeouts, tools for production, rapid development, and managing services, these tools can be applied to WCF web services, and we can use NSB to retry a web service, error report on it, manage the service, and use Saga workflow to manage the business logic in the WCF web service.
![Page 84: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/84.jpg)
NSB Hosting
October 10, 2014By Rich Helton
![Page 85: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/85.jpg)
NSB hosting features
NServiceBus.Host.exe is an executable to install, and uninstall, DLL's using NSB as Windows services. This includes features to add additional configurations
during runtime, to include endpoints. The NServiceBus.Host framework and executable will
streamline the installation process by creating endpoints. It will handle the Windows service installation and provide NSB management features as well.
![Page 86: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/86.jpg)
Host and Visual Studio
NServiceBus.Host.exe is an executable that can be used as a reference in Visual Studio.This is so the service can be DLL, it can generate endpoint template code, and run the DLL in Visual Studio.
![Page 87: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/87.jpg)
Debug
In the Debug properties of the project, we can see NServiceBus.Host.exe running the DLL that is created.
![Page 88: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/88.jpg)
EndpointConfig
NServiceBus.Host.exe will create a default EndpointConfig.cs when it is added to the project's references.
![Page 89: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/89.jpg)
The Host has several deployments
NServiceBus.Host.exe has several configurations to run worker services, installations, creating endpoints, and much more.
![Page 90: NServicebus WCF Integration 101](https://reader030.vdocuments.net/reader030/viewer/2022020718/557d8e64d8b42ad6698b4d9d/html5/thumbnails/90.jpg)
Conclusion
NSB brings a lot of features to the table with a small price.