C++ wrapper class for C# class calling a web servi

2019-09-17 07:50发布

So, I've written a web service in c#, which has a method for signing a hash. This web service is a WCF Service application. Then, I've created a c# Console application where I've written a function to consume this web service. The declaration of the function which calls the web service is that:

class Program
{
public byte[] callWS(string alias, byte[] myHash,string myPassword)
{
    IhashSignSVCClient client = new IhashSignSVCClient();
        byte[] signedData= client.SignandReturn(alias, myhash, myPassword);
        if (signedData != null)
        {
            Console.WriteLine(signedData);
            return signedData;
        }
        return null;

 }
}

This web service works fine. Now I want to build a c++ wrapper class over this c# method, because I want to call this web service from unmanaged code and I thought that creating a c++ wrapper class will be a good idea. Can anyone help me with a kind of a structure of this wrapper class? I haven't understood very well the conversions between c++ and c#. I've created a C++ CLR class library, with a ref class which will contain my c++ method to call this c# method, but I still have some problems with the type of parameters of this function.

1条回答
Deceive 欺骗
2楼-- · 2019-09-17 08:30

If you want to stick to native (unmanaged) C++ (instead of using C++/CLI), your best option might be WWSAPI as that can call a WCF service directly from C++. Although since it's a C-based API, it's a bit of a nuisance to use from C++.

Otherwise, there is extensive documentation about C++/CLI here; in particular marshaling.

查看更多
登录 后发表回答