2011-04-18 76 views
0

嗨 我有一个WCF web服务,它有一个操作,我需要从本机C++调用中调用。我有一个桥梁管理DLL的工作,但我有一个调用具有OUT对象的WCF操作truoble。从托管的C++代码调用C#opeartion'Out'

的C#opearation:

void DoWork(string indxNum, out ErrorWarningsData objerrc)

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

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

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;

但是,当我尝试从WCF调用DoWork的方法服务我收到错误。

这是我的尝试:

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

能有一个人请告诉我如何与 'OUT' 访问oject。 我能找到一些例子来访问[OUT]为int和字符串,但没有为对象

PS:我也跟着下面的链接到WCF服务连接到本地appliaction [链接] HTTP://计算器。 com/questions/686452/create-wcf-service-for-unmanaged -c-clients

回答

0

我不确定你为什么在这些情况下使用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); 
+0

我试过了,但是当我调用方法'client-> DoWork(“4278778”,objEWData)' – abc123 2011-04-18 18:33:23

+1

“时,它仍然会抛出异常。仍然抛出一个异常“?你从来没有提到它抛出一个异常之前,如果它编译,它看起来像你的问题被回答 - 发生异常将表明你正在使用该方法不正确。 – 2011-04-18 18:59:24

0

为了在C++/CLI中传递某些输出参数,您不需要任何额外的标记。语义类似于在本地C++中通过引用传递。

+0

我初始化使用gcroot的对象,所以我得到一个错误,无法从gcroot 转换为 abc123 2011-04-18 16:00:12

+0

gcroot没有一个converstion运营商“T ^%”。它只返回一个T的副本(这应该是正确的,因为无论如何T是一个“指针类型”。如果你想让gcroot变量指向方法返回的新T,那么你必须有临时变量然后将它分配给你的gcroot 变量 – 2011-04-18 16:16:06