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

廉价感情. 提交于 2019-12-12 02:32: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:


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.



来源:https://stackoverflow.com/questions/43333256/c-wrapper-class-for-c-sharp-class-calling-a-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!