使用“Out”调用 C# 操作来自托管 C++代码

发布于 2024-11-02 06:15:21 字数 1534 浏览 1 评论 0原文

你好 我有一个 WCF Web 服务器,它有一个我需要从本机 C++ 应用程序调用的操作。我有一个可以工作的桥接管理 DLL,但我在调用具有 OUT 对象的 WCF 操作时遇到了麻烦。

C# 操作:

void DoWork(string indxNum, out ErrorWarningsData objerrc)

这里 ErrorWarningsData 是 C# Web 服务中的一个类。

这就是我的托管 C++ 代码的样子:

gcroot; Binding1 = gcnew WSHttpBinding();

gcroot;地址1 = gcnew EndpointAddress(gcnew String("http://usatondevlas1.na.praxair.com/Build15/ResourceCenterSVC/ResourceCenter.svc"));

gcroot; client = gcnew HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient(binding1,address1);

gcroot; objEWData = gcnew HelloServiceClient::ServiceReference2::ErrorWarningsData;

但是,当我尝试从 WCF 服务调用 DoWork 方法时,出现错误。

这就是我尝试过的:

client->DoWork("4278779",[Out] objEWData ); 也尝试过, client->DoWork("4278779",[Out] ^% objEWData ); 和, client->DoWork("4278779",[Out] % objEWData );

有人可以告诉我如何使用“OUT”访问对象吗? 我可以找到一些示例来访问 int 和 string 的 [Out],但没有访问对象

PS:我按照以下链接将 WCF 服务连接到本机应用程序 [链接]http://stackoverflow.com/questions/686452/create-wcf-service-for-unmanagement-c-clients

Hi
I have a WCF web serive which has an opeartion i need to call from a native C++ apllication. I have a bridge managed DLL which works, but I am having truoble with calling a WCF operation which has an OUT object.

The C# opearation:

void DoWork(string indxNum, out ErrorWarningsData objerrc)

Here ErrorWarningsData is a class in the C# Web Service.

This is how my Managed C++ code looks like :

gcroot<Binding^> binding1 = gcnew WSHttpBinding();

gcroot<EndpointAddress^> address1 = gcnew EndpointAddress(gcnew String("http://usatondevlas1.na.praxair.com/Build15/ResourceCenterSVC/ResourceCenter.svc"));

gcroot<HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient^> client = gcnew HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient(binding1,address1);

gcroot<HelloServiceClient::ServiceReference2::ErrorWarningsData^> objEWData = gcnew HelloServiceClient::ServiceReference2::ErrorWarningsData;

But when I try to call the DoWork Method from the WCF Service I get an error .

This is what I tried :

client->DoWork("4278779",[Out] objEWData );
Also tried,
client->DoWork("4278779",[Out] ^% objEWData );
And,
client->DoWork("4278779",[Out] % objEWData );

Could some one please tell me how to access the oject with 'OUT'.
I could find some examples to access [Out] for int and string but none for objects

PS: I followed the following to link to connect the WCF service to the native appliaction
[link]http://stackoverflow.com/questions/686452/create-wcf-service-for-unmanaged-c-clients

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦行七里 2024-11-09 06:15:21

我不确定你为什么在这些情况下使用 gcroot 。你可以这样做:

WSHttpBinding ^ binding1 = gcnew WSHttpBinding(); 
EndpointAddress ^ address1 = gcnew EndpointAddress(gcnew String ("http://usatondevlas1.na.praxair.com/Build15/ResourceCenterSVC/ResourceCenter.svc"));
HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient ^ client = gcnew HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient(binding1,address1);
HelloServiceClient::ServiceReference2::ErrorWarningData ^ objEWData = gcnew HelloServiceClient::ServiceReference2::ErrorWarningsData;
client->DoWork("4278779", objEWData); 

I'm not sure why you are using gcroot in these cases. You can just do:

WSHttpBinding ^ binding1 = gcnew WSHttpBinding(); 
EndpointAddress ^ address1 = gcnew EndpointAddress(gcnew String ("http://usatondevlas1.na.praxair.com/Build15/ResourceCenterSVC/ResourceCenter.svc"));
HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient ^ client = gcnew HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient(binding1,address1);
HelloServiceClient::ServiceReference2::ErrorWarningData ^ objEWData = gcnew HelloServiceClient::ServiceReference2::ErrorWarningsData;
client->DoWork("4278779", objEWData); 
涫野音 2024-11-09 06:15:21

您不需要任何额外的标记即可在 C++/CLI 中将某些内容作为输出参数传递。语义类似于本机 C++ 中的引用传递。

You shouldn't need any extra markup in order to pass something as an out parameter in C++/CLI. The semantics are similar to passing by reference in native C++.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文