title: Issues with COM DLL calling WCF Service
body: <p>I have a WCF Service which has a contract like this: (the operation contract is OneWay)</p>
  
  <pre><code>[ServiceContract()]
  public interface IEmpUpdate
  {
      [OperationContract(IsOneWay = true)]
      void SendEmpUpdate(int _empid);
  }
  </code></pre>
  
  <p>I have to call this SendEmpUpdate method from a COM DLL.  I searched in the web and found some examples but that was for vb.  My COM component was developed in C++.  I followed the same steps for doing it in C++.</p>
  
  <p>The Link which I followed:</p>
  
  <p><a href="http://pieterderycke.wordpress.com/2010/10/05/using-the-wcf-service-moniker-to-communicate-between-legacy-com-applications-and-new-net-applications/" rel="nofollow">http://pieterderycke.wordpress.com/2010/10/05/using-the-wcf-service-moniker-to-communicate-between-legacy-com-applications-and-new-net-applications/</a></p>
  
  <p>This link explains about two ways of doing it:</p>
  
  <p>1.Consuming a WCF service using a typed contract
  2.Consuming a WCF service using a MEX endpoint</p>
  
  <p>I tried in both ways: (C++)</p>
  
  <p>The 2nd way (Consuming a WCF service using a MEX endpoint) please see the below code:  </p>
  
  <p>The 2nd way works fine if I change OperationContract IsOneWay to false for SendEmpUpdate.  If its true the Invoke method is failing with HRESULT value 0x80131502 (it seems to be like a 
  ArgumentOutOfRangeException uses the HRESULT COR_E_ARGUMENTOUTOFRANGE)</p>
  
  <hr>
  
  <pre><code>//Importing the tlb:
  
  #import "Employee.tlb" no_namespace named_guids
  
  //Creating the moniker string:
  
  LPTSTR moniker = L"service:mexaddress=net.tcp://localhost:11234/Employee/mex, "
               L"address=net.tcp://localhost:11234/Employee, "
               L"contract=IEmpUpdate, "
               L"binding=nettcpEmpUpdate, ";
  
  //Get the Object:
  
  HRESULT hr = S_FALSE;
  IDispatch* objWsc;
  
  hr = CoGetObject(moniker, NULL, IID_IDispatch, (void**)&amp;objWsc);
  
  if (FAILED(hr))
  {
      Message(TEXT("Client: CoGetObject"), hr);
      return(hr);
  }
  
  DISPID dispid;
  BSTR pOperation = L"SendEmpUpdate";
  
  hr = objWsc-&gt;GetIDsOfNames(
      IID_NULL,
      &amp;pOperation,
      1,
      LOCALE_SYSTEM_DEFAULT,
      &amp;dispid);
  
  if (FAILED(hr))
  {
      Message(TEXT("Client: GetIDsOfNames"), hr);
      return(hr);
  }
  
  DISPPARAMS empIDs;
  VARIANTARG varData[1];
  empIDs.rgvarg = &amp;varData[0];
  
  VariantInit(&amp;empIDs.rgvarg[0]);
  empIDs.rgvarg[0].vt = VT_I4;
  empIDs.rgvarg[0].lVal = 564234; 
  
  empIDs.cArgs = 1;
  empIDs.cNamedArgs = 0;
  empIDs.rgdispidNamedArgs = NULL;
  
  VARIANT result;
  //VariantInit(&amp;result);
  UINT argErr = 0;
  
  EXCEPINFO pExcepInfo;
  memset(&amp;pExcepInfo, 0, sizeof(EXCEPINFO));
  
  hr = objWsc-&gt;Invoke(
      dispid,
      IID_NULL,
      LOCALE_SYSTEM_DEFAULT,
      DISPATCH_METHOD,
      &amp;empIDs, &amp;result, &amp;pExcepInfo, &amp;argErr);
  
  if (FAILED(hr))
  {
      Message(TEXT("Client: Invoke"), hr);
      return(hr);
  }
  </code></pre>
  
  <hr>
  
  <p>The 1st method (Consuming a WCF service using a typed contract) please see the below code:</p>
  
  <p>In the 1st method CoGetObject is failing objEmp is null.</p>
  
  <hr>
  
  <pre><code>//Importing the tlb:
  
  #import "Employee.tlb" no_namespace named_guids
  
  //Creating the moniker string:
  
  LPTSTR moniker = L"address=net.tcp://localhost:11234/Employee, "
               L"contract={52DEEE76-0BAF-31D8-A48B-DA2C50FA2753}, "
               L"binding=nettcpEmpUpdate ";
  
  //Get the Object:
  
  HRESULT hr = S_FALSE;
  IEmpUpdate* objEmp;
  
  hr = CoGetObject(moniker, NULL, __uuidof(IEmpUpdate), (void**)&amp;objEmp);
  
  if (FAILED(hr))
  {
      Message(TEXT("Client: CoGetObject"), hr);
      return(hr);
  }
  </code></pre>
  
  <hr>
  
  <p>Questions:</p>
  
  <ol>
  <li>If I set IsOneWay to true in the 2nd way, it's failing, how to fix this issue?</li>
  <li>Why CoGetObject is failing in the 1st way how to fix it?</li>
  <li>If any one way works 1st or 2nd it would be really helpful.  There are no example in the web.  </li>
  </ol>