Calling C# web services using C++/CLR

Calling C# web services using C++/CLR

To a group of people who might want to try to call web service that has written in VB.NET or C# this is how the way of doing it.

Firstly, I am creating a default web service using C# language.

1.     Open Visual Web Developer or any edition of Visual Studio 2005.

2.     On the File menu, click New Web Site.

The New Web Site dialog box appears.

3.     Under Visual Studio installed templates, click ASP.NET Web Service.

4.     Click Browse.

5.     Click Local IIS.

6.     Click Default Web Site.

7.     Click Create New Web Application.

Visual Web Developer creates a new IIS Web application.

8.     Type the name WebService1.

9.     Click Open.

The New Web Site dialog box appears, with the name of the new Web site in the right-most Location list. The location includes the protocol (http://) and location (localhost). This indicates that you are working with a local IIS Web site.

10.  In the Language list, click the programming language C#.

11.  Click OK.

Visual Web Developer or Visual Studio 2005 creates the new Web service and opens a new class named Service, which is the default Web service. However, in the following procedure you will create a new Web service with a specified name and you will not use the Service class.

 After creating the web service you will find a default web method HelloWorld().

Now add a new C++ CLR console project to the solution.

1.       Open the File menu, click Add then New Project.

2.       Click Visual C++ from the Project types.

3.       Click CLR Console Application from Templates.

4.       Type ConsoleApplication1 or any name you like to use in the Name: textbox.

 

Adding the Web Service as a Component

1.       In Solution Explorer, right-click the name of the Web site, and then click Add Web Reference.

2.     In the URL list, enter the following URL for the Web service, and then click Go:

    http://localhost/WebService1/Service.asmx

3.       Type in HelloWorld in Web reference name: textbox.

4.       Click Add Reference.

 

Add the following code to your C++ console application.

using namespace HelloWorld;
 
int main(array<System::String ^> ^args)
{
      HelloWorld::Service ^ws = gcnew HelloWorld::Service;
     
      Console::WriteLine(ws->HelloWorld());
  return 0;
}

Now, I will not make the mistake I made again. You will probable realize you do not use

HelloWorld.Service

but

HelloWorld::Service

and you use gcnew instead of new keyword.

Expose more and give me feedback. Have fun

Additional resources:

http://msdn2.microsoft.com/en-us/library/8wbhsy70(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/a86z84tw(VS.80).aspx 

Advertisements

About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress (http://www.pcworld.com/article/206455/Microsoft_Live_Spaces_Moves_to_WordPress_An_FAQ.html) till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s