Building WCF service applications using method 2: Self-hosting programmatically directly from the application

Add the binding properties, create the service host with an instance of the required service class and open the service.


Before starting

  1. Add a reference to the custom channel IBM.XMS.WCF.dll file to the project. The IBM.XMS.WCF.dll is in the WMQInstallDir\bin where WMQInstallDir is the directory that IBM MQ is installed in.
  2. Add a using statement to the IBM.XMS.WCF namespace, for example: using IBM.XMS.WCF
  3. Create an instance of the channels binding element and endpoint as described in: Create a WCF custom channel by suppling binding and endpoint information programmatically


If changes to the binding properties of the channel are required, then complete the following steps:

  1. Add the binding properties to transportBindingElement as shown in the following example:
    SoapJmsIbmTransportBindingElement transportBindingElement = new SoapJmsIbmTransportBindingElement();
    Binding binding = new CustomBinding(new TextMessageEncodingBindingElement(), transportBindingElement);
    Uri address = new Uri("jms:/queue?destination=SampleQ@QM1&connectionFactory=
                            connectQueueManager(QM1)&initialContextFactory=com.ibm.mq.jms.Nojndi");
    
  2. Create the service host with an instance of the required service class:
    ServiceHost service = new ServiceHost(typeof(MyService));
    
  3. Open the service:
    service.AddServiceEndpoint(typeof(IMyServiceContract), binding, address);
    service.Open();
    ...
    service.Close();
    

Parent topic: Building and hosting services for WCF