Consumig WebService from C++.
-
Hi all, I'm trying to find the best/easiest way to consume a WebService in my application which is written in C/C++. I've seen and tried numerous examples over the course of the last few days, and there seems to be pros and cons no matter which way I go. I thought I'd ask you folks your opinion. I turned on the "/crl" option on in my project, and added a WebReference. I was able to call the WebService without any problems, but I'm unsure how to handle exceptions when something goes wrong (ie: address is no longer valid). If everything is up and running and things are successful, there are no problems.
Test_WSService obtws;
try
{
obtws.Url = "http://localhost:8088/mockObtain\_WSSoapBinding1";
obtws.UpdateObject ( "A", "B", "C" );
}
catch ( ??? )
{
}With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file. My knowledge of COM is almost nil. I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well. Whats your past experiences, recommendation? Anything you could forward would be helpful. Cheers. Mike.
-
Hi all, I'm trying to find the best/easiest way to consume a WebService in my application which is written in C/C++. I've seen and tried numerous examples over the course of the last few days, and there seems to be pros and cons no matter which way I go. I thought I'd ask you folks your opinion. I turned on the "/crl" option on in my project, and added a WebReference. I was able to call the WebService without any problems, but I'm unsure how to handle exceptions when something goes wrong (ie: address is no longer valid). If everything is up and running and things are successful, there are no problems.
Test_WSService obtws;
try
{
obtws.Url = "http://localhost:8088/mockObtain\_WSSoapBinding1";
obtws.UpdateObject ( "A", "B", "C" );
}
catch ( ??? )
{
}With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file. My knowledge of COM is almost nil. I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well. Whats your past experiences, recommendation? Anything you could forward would be helpful. Cheers. Mike.
Mike Doner wrote:
With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file.
Mike Doner wrote:
I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well.
Mike Doner wrote:
Whats your past experiences, recommendation?
Yes, we have done the same thing. I used WSDL[^] to generate a C# proxy source file then built that into an assembly with a wrapper class that changes the URL based on incoming parameters. This wrapper is then used by C++/CLI DLL Project that exports a native C++ class that is used by native EXE projects. The WSDL generated class derives from
System.Web.Services.Protocols.SoapHttpClientProtocol
which has a.URL
property. -
Mike Doner wrote:
With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file.
Mike Doner wrote:
I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well.
Mike Doner wrote:
Whats your past experiences, recommendation?
Yes, we have done the same thing. I used WSDL[^] to generate a C# proxy source file then built that into an assembly with a wrapper class that changes the URL based on incoming parameters. This wrapper is then used by C++/CLI DLL Project that exports a native C++ class that is used by native EXE projects. The WSDL generated class derives from
System.Web.Services.Protocols.SoapHttpClientProtocol
which has a.URL
property.Thank you for your reply. As I said, this is all pretty new to me, so I'm doing a bit of feeling around for getting it to work. I was able to create a C# proxy without any problems, and from a C# project, I can call the WebService. I've created a C# Class that has a WebService, with all the parameters I need, including setting the URL. Now, to call this from the C++ side... Were you suggesting all the C# stuff being in a .DLL, then calling those functions from the C++ side? Is there a way to put a .cs into a project and have it all compile together into one project? I found a sample online (may have been here on CP), that has a MFC project, and it shows how to use a C# object from the MFC side, including all the string marshalling. Is there an easier way? Thanks again... I'm getting closer! ;-)
-
Thank you for your reply. As I said, this is all pretty new to me, so I'm doing a bit of feeling around for getting it to work. I was able to create a C# proxy without any problems, and from a C# project, I can call the WebService. I've created a C# Class that has a WebService, with all the parameters I need, including setting the URL. Now, to call this from the C++ side... Were you suggesting all the C# stuff being in a .DLL, then calling those functions from the C++ side? Is there a way to put a .cs into a project and have it all compile together into one project? I found a sample online (may have been here on CP), that has a MFC project, and it shows how to use a C# object from the MFC side, including all the string marshalling. Is there an easier way? Thanks again... I'm getting closer! ;-)
Mike Doner wrote:
Were you suggesting all the C# stuff being in a .DLL, then calling those functions from the C++ side?
Sort of. C++/CLI provides the combined use of Native Code and Managed Code. So it creates a very natural environment for marshalling. By building your C# proxy into an assembly it becomes available to C++/CLI projects as a Managed class when you add the Reference to the assembly.
Mike Doner wrote:
Is there an easier way?
An easier way to perform Marshalling? No, marshalling is nothing new[^]. It is what it is, we can't change it.