其实没什么难度,只是要调发送的xml格式,建议使用SoapUI调好,再粘到项目中
就是使用 msxml因为是mfc的东西,要在项目中设置在共享DLL中使用MFC
还有要在调用的服务后面加?wsdl解释成xml格式
代码
webservice
namespace WebService
{
///
/// Service1 的摘要说明
///
[WebService(Namespace = "https://www.jb51.net/")]
[WebServiceBinding(COnformsTo= WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string SayHello(string name)
{
return "Hello "+name;
}
}
}
头文件
[code]
#pragma once
#include "stdafx.h"
#include "Atlbase.h"
//#import "msxml.dll"
#import "msxml4.dll"
using namespace MSXML2;
#include
#include
using namespace std;
调用代码
//sb.append("
sb.append("
sb.append("
sb.append("
sb.append("
xmlrequest->send(_variant_t(sb.c_str()));//发道数据
BSTR bstrbody;
xmlrequest->get_responseText(&bstrbody);//得到返回数据
_bstr_t bstrtbody(bstrbody);
printf("%s\n",(LPCTSTR)bstrtbody);
MSXML2::IXMLDOMDocument2Ptr m_xmldoc;
m_xmldoc.CreateInstance(__uuidof(MSXML2::DOMDocument));
m_xmldoc->loadXML(bstrbody);
MSXML2::IXMLDOMNodePtr node = m_xmldoc->documentElement->firstChild;
LPCTSTR str = (LPCTSTR)node->nodeName;
string str2=(string)m_xmldoc->documentElement->text;
cout<
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
CoUninitialize();
printf("program end\n");
return 0;
}