如何将数据提取从C#/ WCF代码传递给托管C ++

问题描述:

大家好,



能告诉我吗如何将C#/ WCF代码(应用程序)的数据传输传递给C ++ / CLI代码方法。





从C#代码我可以传递数据合同,但是在托管(C ++ / CLI) )代码方如何将该数据合同作为参数接收?



请用一些例子给我解释。





换句话说,托管C ++中datacontract的等价物是什么,所以我可以将它作为参数传递给方法,可以从C#中调用。





////////


$ c $ b在C#应用程序中,我有一些像这样的代码

SubscriptionDataContract subscriptionData = null;

subscriptionData = new SubscriptionDataContract();



从C#代码应用程序,我需要在托管C ++中调用以下方法(C ++ / CLI)

我要传递上述数据联系人。



ClientSideWrapper.ClientInterface iClient = new ClientSideWrapper.ClientInterface( );



iClient.sendMessage(句柄,订阅数据);





我需要在Managed C ++(C ++ / CLI)中创建一个方法,这样我就可以将该数据从C#传递给Managed C ++ cod e并执行所需的处理。





但似乎托管C ++不会采用datacontract,因为我得到以下错误:

在Manged C ++中使用此函数。





EXPORT_VOID sendMessage(handle_t binding,DataContracts :: NotificationDataContract ^ dc) ;





错误C3395:'sendMessage':__ declspec(dllexport)无法应用于具有__clrcall调用约定的函数





请告诉我如何处理这种情况。



感谢您的帮助。



谢谢,

Sudhakar

Hi All ,

Could you please let me know How to pass a datacontract from a C#/WCF code (application) to C++/CLI code method.


From C# code i can pass a data contract, but at managed (C++/CLI) code side how can I receive that data contract as a parameter?

Please explain me with some examples.


in other words what is the equvialent of datacontract in managed C++ , so that i can pass it to the method as a parameter which can be called from C#.


////////

in C# application, i have some code like this
SubscriptionDataContract subscriptionData = null;
subscriptionData = new SubscriptionDataContract();

From C# code application , I need to call the below method in Managed C++ (C++/CLI)
in which i want to pass the above data contact.

ClientSideWrapper.ClientInterface iClient = new ClientSideWrapper.ClientInterface();

iClient.sendMessage(handle,subscriptionData);


I need to create a method in Managed C++ (C++/CLI) , so that i can pass that datacontract (details) from C# to Managed C++ code and do the required processing.


But it seems Managed C++ will not take datacontract as i am getting the below error:
with this function in Manged C++ .


EXPORT_VOID sendMessage(handle_t binding,DataContracts::NotificationDataContract^ dc);


error C3395: 'sendMessage' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention


Please let me know how to handle this scenario.

Appreciate your help.

Thanks,
Sudhakar

请看我的评论问题。



数据合约不能作为参数传递。数据契约是一种概念结构,表示为一组相关数据类型的组合,以及这些类型和成员的一些数据契约属性;更准确地说,这是一组不变的:当你改变它时,类型和标记为合同一部分的成员保持不变并保持其结构关系,合同保持不变尽管类型集有所改变。这样,这可能是某些产品的生命周期,甚至是一些数据标准的不变量。



正如你所看到的,这都是纯粹的元数据,这很漂亮难以表达为数据(但可能)。这不是你作为参数传递的内容。



基于数据合同的序列化采用随合同创建的任何对象图(在一般情况下,甚至不一定是树,任意图形)并将其全面序列化为任何流。稍后,可以将此流反序列化回对象图,逻辑上与原始对象图相同的内存结构。



请参阅:

使用数据合同:
https:// msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx




因此,每次,每个数据实例都表示为数据图或流内容;这些陈述是相互可逆和全面的。是的,对流或图的引用可以传递到引用保持有效的任何地方,所以没有这样的问题。



如果你有一些相关的问题,请随时询问您的后续问题。



-SA
Please see my comment to the question.

Data contract cannot be passed as a parameters. Data contract is the conceptual structure expressed as a combination of some set of related data types and some data contract attributes over those types and members; more exactly, this is some invariant of that set of types: when you change it but the types and the members marked as the part of contract remains the same and keep their structural relationships, the contract remains the same despite of the change in the type set. This way, this can be the invariant of some product's life time, or even some data standard.

As you can see, this is all pure metadata, which is pretty hard to express as data (but possible). This is not what you pass "as a parameter".

Serialization based on data contract takes any object graph created with the contract (in general case, not even necessarily a tree, any arbitrary graph) and comprehensively serialize it into any stream. Later on, this stream can be deserialized back to the object graph, a memory structure logically identically to the original object graph.

Please see:
Using Data Contracts:
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx
.

Therefore, each time, each instance of the data is represented either as a data graph, or a stream content; and these representations are mutually reversible and comprehensive. And yes, the reference to a stream or to a graph can be passed anywhere where a reference remains valid, so there is no such problem.

If you have some related problems, feel free to ask your follow-up questions.

—SA