WCF callbacks under C++/CLI

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.
 
C

Carl Daniel [VC++ MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top