0

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

abc123
  • 3
  • 2

2 Answers2

0

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++.

MikeP
  • 7,829
  • 33
  • 34
  • I initialize the object using gcroot, So I get an error saying cannot convert from gcroot to – abc123 Apr 18 '11 at 16:00
  • gcroot does not have a converstion operator to "T^%". It only returns a copy of T (which should be fine since T is a "pointer type" anyways. If you want the gcroot variable to point to the new T that is returned by the method, you'll have to have temporary variable of T^ that is passed into the method, and then assign that to your gcroot variable. – Matt Smith Apr 18 '11 at 16:16
0

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); 
Matt Smith
  • 17,026
  • 7
  • 53
  • 103
  • I tried it , but it still throws an exception when I call the method `client ->DoWork("4278778",objEWData)` – abc123 Apr 18 '11 at 18:33
  • 1
    "still throws an exception"? You never mentioned it throwing an exception before. If it compiles, it looks like your question is answered--an exception occurring would indicate you are using the method incorrectly. – Matt Smith Apr 18 '11 at 18:59