14

I'm using NSIS to build an installer and as part of that installer I get the details for a WCF Service (i.e. Url, User Name and Password). I need to validate these details.

In C# I create a Service Reference and simply do the following:

var proxy = new ServiceClient(httpsBinding, serviceEndpointAddress);
proxy.ClientCredentials.UserName.UserName = userName;
proxy.ClientCredentials.UserName.Password = password;

try
{
    proxy.Open();
}
catch (EndpointNotFoundException ex)
{
    // Return the end point's not valid
}
etc

Now I need to do this in C++ so it can be called from NSIS (I've investigated methods of calling C# from NSIS and they all seem to be overkill for what I want to do). I've managed to convert the code that generates the binding and the end point address however I'm stuck on creating the ServiceClient.

I've added a "Web Reference" to the project but there's not the equivalent of ServiceClient in the ServiceReference namespace. This:

ServiceReference::ServiceClient ^service = gcnew ServiceReference::ServiceClient(httpsBinding, endpointAddress);

doesn't compile as:

'ServiceClient': is not a member of 'ServiceReference'

So how do I create the client?

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Have you put the `using namespace ServiceMainNamespace` directive relative to the web service you added ? – alexbuisson Jul 31 '13 at 06:40
  • @alexbuisson - I can't seem to find that namespace. Can you add a link to the documentation. – ChrisF Jul 31 '13 at 07:45
  • Ok sorry, that namespace doesn't exist :) it was just an example to recall that in C# the ServiceClient class come from an assembly, and you should be able to found its name. Thaa assembly should be in the reference list of your C++/CLI and in the .cpp file where you use `ServiceClient`you must put a using directive. As in C# ! – alexbuisson Jul 31 '13 at 09:22
  • @alexbuisson - ah, I see what you're driving at. However I'm using the fully qualified name already. All I've got is something called `ServiceReference::Service` but that doesn't have any of the methods I'm expecting. – ChrisF Jul 31 '13 at 09:30

3 Answers3

0

have you tried gSOAP?

http://gsoap2.sourceforge.net/

that's what we're using to access WS* from C++ programs.

Steffen Roller
  • 3,464
  • 25
  • 43
  • I don't really need anything that complex. All I need to do is verify the url, user name and password. I don't need to get any data. – ChrisF Jul 28 '13 at 16:55
0

you can make a nice work around, Create a C# DLL, use regasm to register this DLL, then you can use it from your C++ program.

TMMDev
  • 473
  • 1
  • 5
  • 10
  • This is overkill for something that's only called once from the installer just to validate the account details. – ChrisF Jul 31 '13 at 14:58
0

In the end I went with using the NSIS "Call .NET DLL methods plugin" which was really overkill for what I needed to do, but I needed a solution that worked and I ran out of time.

ChrisF
  • 134,786
  • 31
  • 255
  • 325