2

I have simple web service apllication, created with C#. I need to call addNumbers method from MFC form application. What is the easiest way to do that? I suppose I can't expect some easy way like C# web service client application.

namespace WebApplication
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public double addNumbers(double value1, double value2)
        {
            return value1 + value2;
        }
    }
}

    namespace WebApplication
    {
        /// <summary>
        /// Summary description for WebService1
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {

            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }

            [WebMethod]
            public double addNumbers(double value1, double value2)
            {
                return value1 + value2;
            }
        }
    }
vico
  • 17,051
  • 45
  • 159
  • 315
  • look at this answer: http://stackoverflow.com/questions/10106816/how-to-contruct-httpsendrequest-method-of-wininet/10133408#10133408, you should be able to adopt it to your needs – marcinj Oct 16 '14 at 14:05

2 Answers2

3

There is Microsoft's REST Services for C++ toolkit that has plenty of native client-side web calling routines.

There is Windows Web Services that is a native equivalent of WCF Web services, only written in C/C++ so its much faster and better :)

There is libCurl that is a standard web-calling C library and can be used for accessing any web server system

There is Microsoft's ATL Server that also have Web service client routines. Point it at your wsdl and it'll generate the client code.

There is Microsoft's MFC CHtmlView class that allows you to navigate to a web URL. Technically designed to call web servers and display HTML pages in a MFC dialog, it can still be used to call your web service, but you'll have to parse the result, which depending how you've coded it, might be easy or there again it might be SOAP.

There's also a COM web services client from Microsoft too, but IIRC that was deprecated a few years back.

So yes.. generally it is as easy as a C# web services client. I don't know why people think it wouldn't be! If you want a recommendation, I'd probably go for the WWS as it is designed to be identical to the WCF stuff, so it will work. WCF's SOAP has a 'loose' policy towards interoperability.

gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
2

I have been using the C++ REST SDK, and it has been working very well. Surprisingly easy to use, and several other nice utilities (i.e. json tools, etc). So, if you can support REST with your C# services, this would be an easy way to hook them up. Good luck.

The code would look similar to the following:

#include <windows.h>
#include "cpprest\json.h"
#include "cpprest\http_client.h"

pplx::task<void> _CallService()
{
    web::http::client::http_client client { U("http://localhost:8080") };
    return client.request(web::http::methods::GET, U("service_name/foo")).then([&](web::http::http_response response)
    {
        auto status { response.status_code() };
        int bodyLength = response.headers().content_length();
    });
}

int main()
{
    Concurrency::task<void> t = _CallService();
    t.wait();
    return 0;
}
Jeff
  • 2,495
  • 18
  • 38