I have a WCF Service which has a contract like this: (the operation contract is OneWay)
[ServiceContract()]
public interface IEmpUpdate
{
[OperationContract(IsOneWay = true)]
void SendEmpUpdate(int _empid);
}
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++.
The Link which I followed:
This link explains about two ways of doing it:
1.Consuming a WCF service using a typed contract 2.Consuming a WCF service using a MEX endpoint
I tried in both ways: (C++)
The 2nd way (Consuming a WCF service using a MEX endpoint) please see the below code:
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)
//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**)&objWsc);
if (FAILED(hr))
{
Message(TEXT("Client: CoGetObject"), hr);
return(hr);
}
DISPID dispid;
BSTR pOperation = L"SendEmpUpdate";
hr = objWsc->GetIDsOfNames(
IID_NULL,
&pOperation,
1,
LOCALE_SYSTEM_DEFAULT,
&dispid);
if (FAILED(hr))
{
Message(TEXT("Client: GetIDsOfNames"), hr);
return(hr);
}
DISPPARAMS empIDs;
VARIANTARG varData[1];
empIDs.rgvarg = &varData[0];
VariantInit(&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(&result);
UINT argErr = 0;
EXCEPINFO pExcepInfo;
memset(&pExcepInfo, 0, sizeof(EXCEPINFO));
hr = objWsc->Invoke(
dispid,
IID_NULL,
LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
&empIDs, &result, &pExcepInfo, &argErr);
if (FAILED(hr))
{
Message(TEXT("Client: Invoke"), hr);
return(hr);
}
The 1st method (Consuming a WCF service using a typed contract) please see the below code:
In the 1st method CoGetObject is failing objEmp is null.
//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**)&objEmp);
if (FAILED(hr))
{
Message(TEXT("Client: CoGetObject"), hr);
return(hr);
}
Questions:
- If I set IsOneWay to true in the 2nd way, it's failing, how to fix this issue?
- Why CoGetObject is failing in the 1st way how to fix it?
- If any one way works 1st or 2nd it would be really helpful. There are no example in the web.