简体   繁体   中英

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

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 ac# 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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM