How do I create a web/wcf service client in C++?
Asked Answered
H

3

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?

Hurrah answered 19/7, 2013 at 12:8 Comment(4)
Have you put the using namespace ServiceMainNamespace directive relative to the web service you added ?Consignor
@Consignor - I can't seem to find that namespace. Can you add a link to the documentation.Hurrah
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 ServiceClientyou must put a using directive. As in C# !Consignor
@Consignor - 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.Hurrah
H
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.

Hurrah answered 2/9, 2013 at 10:42 Comment(0)
B
0

have you tried gSOAP?

http://gsoap2.sourceforge.net/

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

Bassorilievo answered 25/7, 2013 at 20:2 Comment(1)
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.Hurrah
A
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.

Alloplasm answered 31/7, 2013 at 11:27 Comment(1)
This is overkill for something that's only called once from the installer just to validate the account details.Hurrah
H
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.

Hurrah answered 2/9, 2013 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.