title: COM/ActiveX DLL to consume WCF service
body: <p>I am trying to extend an application which supports COM/ActiveX objects. The COM dll needs to send some data to other system on local network for further processing and actions.</p>
  
  <p>I have tested a basic WCF Host-Client setup and it works fine from console client to console host. But now I need to send data through a client in com-visible dll.</p>
  
  <p>This is the code of the dll :</p>
  
  <pre><code>namespace Client
  {
  [Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]
  [ComVisible(true)]
  public interface ISend
  {
      [DispId(1)]
      bool SendData(string msg);
  }
  [ClassInterface(ClassInterfaceType.None), Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), ProgId("Client.Send")]
  [ComVisible(true)]
  public class Send : ISend
  {
      static BasicHttpBinding binding = new BasicHttpBinding();
      static EndpointAddress endpoint = new EndpointAddress(new Uri("http://192.168.1.6:8000/WCFHost/Service/GetData"));
  
      GetDataClient client = new GetDataClient(binding, endpoint);
      [ComVisible(true)]
      public bool SendData(string msg)
      {       
          try
          {
              if (client.getData(msg))
              {
                  client.Close();
                  return true;
              }
              else
              {
                  client.Close();
                  return false;
              }
          }
          catch (Exception e)
          {
              client.Abort();
              return false;
          }
      }
  }
  } 
  </code></pre>
  
  <p>The dll works fine as a reference but cannot create object through target application(It has the functionality to access COM/ActiveX objects). When I try to access the dll by :</p>
  
  <pre><code>obj = CreateObject ("Client.Send");
  obj.SendData("Hello")
  </code></pre>
  
  <p>It says : </p>
  
  <p><code>COM/object handle is null</code></p>
  
  <p>on second line nothing more!</p>
  
  <p>I created a com-visible dll in similar way using Remoting to achieve this and it worked like a charm. But now its not working as a WCF Client.</p>
  
  <p>It would be really appreciated if someone could point out what I am doing wrong.</p>
  
  <p>I had moved to Remoting where this was not a problem, but I was suggested to stay away from it and achieve this through WCF.</p>
  
  <p>P.S : I am new to C# so please excuse any stupid mistakes.</p>