WCF callbacks under C++/CLI

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I am trying to figure out how to implement WCF under C++/CLI. Most
examples involve C# code. For instance, an interface is defined like
this:

interface IMyContractCallback
{
[OperationContract]
void OnCallback();
}

[ServiceContract(CallbackContract = typeof(IMyContractCallback))]
interface IMyContract
{
[OperationContract]
void DoSomething();
}

As far as I can tell, there are no attributes available under C++/CLI
for OperationContract, ServiceContract, or CallbackContract. I know I
can define IMyContract like this:

public interface class IMyContract
{
void DoSomething();
};

It does not seem to require [OperationContract]. However, it seems
that I do need some way to tell IMyContract that the callback is via
IMyContractCallback.
 
Jim said:
I am trying to figure out how to implement WCF under C++/CLI. Most
examples involve C# code. For instance, an interface is defined like
this:

interface IMyContractCallback
{
[OperationContract]
void OnCallback();
}

[ServiceContract(CallbackContract = typeof(IMyContractCallback))]
interface IMyContract
{
[OperationContract]
void DoSomething();
}

As far as I can tell, there are no attributes available under C++/CLI
for OperationContract, ServiceContract, or CallbackContract. I know I
can define IMyContract like this:

public interface class IMyContract
{
void DoSomething();
};

It does not seem to require [OperationContract]. However, it seems
that I do need some way to tell IMyContract that the callback is via
IMyContractCallback.

You just need a little secret sauce:

using namespace System::ServiceModel;

interface class IMyContractCallback
{
[OperationContract]
void OnCallback();
};

[ServiceContract(CallbackContract = IMyContractCallback::typeid)]
interface class IMyContract
{
[OperationContract]
void DoSomething();
};


Compile with /clr /FU System.ServiceModel.dll /AI <path to wcf binaries>

-cd
 
Back
Top