Thursday, November 15, 2012

WCF Service in a console app

Create a new console app:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Add Reference.... Select System.ServiceModel from the .NET tab and click OK.
using System.ServiceModel;
using System.ServiceModel.Description;

namespace WCFConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(Service1));
            host.Open();
            Console.Write("Service is up and running");
            Console.ReadKey();
            host.Close();
        }
    }

    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GreetingMessage(string Name);
    }

    public class Service1 : IService1
    {
        public string GreetingMessage(string name)
        {
            return "Welcome to WCF " + name;
        }
    }
}

Add App.config:

  
    
      
        
        
          
          
            
          
        
        
        
          
            
          
        
      
    
    
      
        
          
          
          
          
        
      
    
  

soapUI Compatible App.config:
Remember to activate WS-A options in your request:
Add default wsa:Action
Add default wsa:To


  
    
    
    
      
        
          
            
          
        
      
    
    

    
      
        
        
          
          
            
          
        
        
        
          
            
          
        
      
    
    
      
        
          
          
          
          
        
      
    
  
  
  

No comments: