2011-04-18 24 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