How to Use VC ++ 6.0 to develop Web service client

Source: Internet
Author: User
Tags soap client xml parser

If you wanna use VC ++ 6.0 to develop application procedure of web service client, your machine have to install soap toolkit3.0 and Microsoft XML Parser! The next task, I will discuss how to use Microsoft soap toolkit3.0 to establish a simple application procedure.

First of all, you have to be familiar with how to use com programme, especially the smart pointer of COM. I am gonna talk about sample class for soap. before this, you have to import class type library that you need. the path is "C:/program files/common files/mssoap/binaries/mssoap1.dll "! The content of class type library will be translated or converted into COM smart pointer in order to describe

Interface of COM. because soap heavily depends on XML, you have to use Microsoft XML parser to handle XML. microsoft XML parser is contained in msxml3.dll file, which you shoshould import before you import mssoap1.dll as following code:

# Import "msxml3.dll" <# import <msxml4.dll> some this like>
Using namespace msxml2;

# Import "C:/program files/common files/mssoap/binaries/mssoap1.dll "/
Exclude ("istream", "isequentialstream", "_ large_integer ",/
"_ Ularge_integer", "tagstatstg", "_ filetime ")
Using namespace mssoaplib; <using namespace mssoaplib30>

Above-mentioned Code, you must contain on your application procedure and

Add them head file as usual. If you really wanna establish soap client application

Procedure, you shoshould complete the next three steps:

1. Assigning and connect web service;

2, preparing and sending message;

3, reading information that returned from web service. I must introduce some classes for you before we start to write our main code.

Soapconnectorptr class. using it like this:

1. Create object of soapconnector class as following code:

Isoapconnectorptr connector;
Connector. createinstance (_ uuidof (httpconnector ));

2. Assign web address as following code:

Connector-> property ["endpointurl"] = "some URL pointing to Web Service ";

If you wanna come to understand property and the value of property, please check other reference. Here, I just talk about address property.

3. Connect web service like this:

Connector-> connect ();

4. Assign soapaction like this:

Connector-> property ["soapaction"] = "some URL ";

5. Start up message handler:

Connector-> beginmessage ();

Here, you shocould add message code between beginmessage () and endmessage () and in the and, the endmessage () function will send message to web service.

Above details/the remarks is about how to connect web service, and then, I will introduce how to create and prepare message.

Using soapserializer class establish SOAP message which will be sent to Web Service. The object of soapserializer class must connect with the object of soapconnector class before communicating with Web Service. The initialization

Soapserializer will establish internal connection. The initialization parameter is

Inputstream.

Create object of soapserializer class and using inputstream initialize it as follow code:

Soapserializerptr serializer;

Serializer. createinstance (_ uuidof (soapserializer ));

Serializer-> Init (_ variant_t (iunknown *) connector-> inputstream ));

SOAP request as following code:

<Soap: envelope xmlns: Soap = "Soap namespace">
<Soap: Body>
<M: somemethodname xmlns: M = "Some namespace">
<Someparameter> someparametervalue </someparameter>
<M: somemethodname>
</Soap: Body>
</Soap: envelope>

But how to use this method? Let's start to decribe them.

Serializer-> startenvelope ("Soap ","","");

Serialsuppliers-> startbody (""); // The main information

Serializer-> startelement ("somemethodname", "M ");

Serializer-> writestring ("someparametervalue ");

Serializer-> writestring ("do something here ...");

 

Serializer-> endelement ();
Serializer-> endelement ();
Serializer-> endbody ();
Serializer-> endenvelope ();

Connector-> endmessage (); // return message to Web Service

The last step. We shoshould read information that returned from web service. Using soapreader class to read information. The next code is about response information by Web Service returned.

<Soap: envelope xmlns: Soap = "Soap namespace">
<Soap: Body>
<M: somemethodnameresponse xmlns: M = "Some namespace">
<Return> someresult </return>
<M: somemethodnameresponse>
</Soap: Body>
</Soap: envelope>

Using outputstream to read object of soapreader information. Create object

Soapreader class and connect outputstream.

Isoapreaderptr reader;
Reader. createinstance (_ uuidof (soapreader ));
Reader-> load (_ variant_t (iunknown *) connector-> outputstream ));

Reader-> rpcresult-> text; // read text.

Above all these is about how to use soap. The next article, I will write some codes as example. See you next article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.