#include "stdafx.h"
#import "msxml4.dll" 
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap1.dll" \
            exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
                    "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象CWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0; // 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
CoInitialize(NULL); ISoapSerializerPtr Serializer;
    ISoapReaderPtr Reader;     ISoapConnectorPtr Connector; // Connect to the service
Connector.CreateInstance(__uuidof(HttpConnector));
Connector->Property["EndPointURL"] = "http://www.w3schools.com/webservices/tempconvert.asmx";
Connector->Connect();
Connector->Property ["SoapAction"] = "http://tempuri.org/CelsiusToFahrenheit";
// Begin message
Connector->BeginMessage();
// Create the SoapSerializer
Serializer.CreateInstance(__uuidof(SoapSerializer));
// Connect the serializer to the input stream of the connector
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
// Build the SOAP Message
Serializer->startEnvelope("soap","","");  
Serializer->startBody("");
Serializer->startElement("CelsiusToFahrenheit","http://tempuri.org/","",""); Serializer->startElement("Celsius","","","");
Serializer->writeString("12");
Serializer->endElement();

Serializer->endElement();
Serializer->endBody();
Serializer->endEnvelope();

    // Send the message to the web service
Connector->EndMessage(); // Read the response
Reader.CreateInstance(__uuidof(SoapReader)); // Connect the reader to the output stream of the connector
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),"");
Reader->Envelope->text; // Display the result
if(Reader->Fault != NULL){
MSXML2::IXMLDOMElementPtr s = Reader->faultstring;
printf("Fault: %s\n",(const char *)s->text);
}else{
printf("Answer: %s\n", (const char *)Reader->RPCResult->xml);
}
CoUninitialize();
} return nRetCode;
}