MSXML + SOAP Toolkit calls Web Service C ++ examples.

xiaoxiao2021-03-06  90

#include

#import "msxml4.dll"

USING NAMESPACE MSXML2;

#import "C: / Program files / compon files / mssoap / binaries / mssoap30.dll" /

Exclude ("iStream", "IrrorInfo", "ISEQUENTIALSTREAM", "_large_integer", / /

"_Ularge_integer", "tagstatstg", "_filetime")

Using Namespace MSSOAPLIB30;

Void Add ()

{

Isoapserializerptr serializer;

IsoapReaderptr Reader;

IsoapConnectorptr Connector;

// Connect to the service.

Connector.createInstance (__ uuidof (httpconnector30));

Connector-> Property ["endpointURL"] = "http://myserver/soap3docsample/docsample1/server/docsample1.wsdl";

CONNECTOR-> Connect ();

// begin the message.

// Connector-> Property ["soapaction"] = "URI: AddNumBers";

Connector-> Property ["soapaction"] = "http://tempuri.org/docsample1/Action/sample1.addnumbers";

CONNECTOR-> BeginMessage ();

// Create The Soapserializer Object.

Serializer.createInstance (__ uuidof (soapserializer30);

// Connect The Serializer Object To The Input Stream of The Connector Object.

Serializer-> Init (_variant_t ((iunknown *) connector-> inputstream);

// build the soap message.

Serializer-> Startenvelope (",", "" ");

Serializer-> StartBody ("");

Serializer-> StartElement ("AddNumBers", "http://tempuri.org/docsample1/message/" "," ");

Serializer-> StartElement ("Numberone", ",", "")

Serializer-> WriteString ("5");

Serializer-> endelement ();

Serializer-> StartElement ("Numbertwo", ",", "");

Serializer-> WriteString ("10");

Serializer-> endelement (); serializer-> endelement ();

Serializer-> endbody ();

Serializer-> EndENVelope ();

// dend the message to the xml web service.

CONNECTOR-> endMessage ();

// read the response.

Reader.createInstance (__ uuidof (SoapReader30));

// Connect The Reader to The Output Stream of The Connector Object.

Reader-> Load (_VARIANT_T ((iunknown *) connector-> outputstream), "" "

// Display the result.

Printf ("ANSWER:% S / N", (const char *) reader-> rpcResult-> text);

}

int main ()

{

Coinitialize (NULL);

Add ();

Couninitialize ();

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-123006.html

New Post(0)