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 should 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 should 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 should 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 send to web service.The Object of SoapSerializer class must connect with the Object of SoapConnector class before communicating with web service.The initialization of
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","","");
Serialzier->startBody(""); //the main information
Serializer->startElement("someMethodName","","","m");
Serializer->WriteString("someParameterValue") ;
Serializer->writeString("do sth here...");
Serializer->endElement();
Serializer->endElement();
Serializer->endBody();
Serializer->endEnvelope();
Connector->EndMessage();// Return message to web service
The last step.we should 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 of
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.