Visual C++下Web Service Client的实现 出错,大家帮帮忙

meibin1110 2008-07-15 02:47:04


#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;
}
...全文
171 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lza7 2009-02-06
  • 打赏
  • 举报
回复
少了什么东西啊?
我也碰到了同样的问题。
分享一下啊
Higgs玻色子 2008-07-16
  • 打赏
  • 举报
回复
...............
Higgs玻色子 2008-07-16
  • 打赏
  • 举报
回复
问题解决了,少了东西
  • 打赏
  • 举报
回复
帮你鼎!
Higgs玻色子 2008-07-15
  • 打赏
  • 举报
回复
这个问题没人回答?还是问错地方了?
meibin1110 2008-07-15
  • 打赏
  • 举报
回复
没人帮我顶,我自己顶。
meibin1110 2008-07-15
  • 打赏
  • 举报
回复
http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit
得不到正确结果,运行出错。
大家给给意见。
谢谢!!!

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧