In fact, there is no difficulty, just to adjust the sent XML format, recommended to use SOAPUI tune, and then stick to the project
is to use MSXML because it's MFC stuff, to set up in the project to use MFC in a shared DLL
And to add the WSDL to the XML format after the invoked service.
Code
WebService
Copy Code code as follows:
Using System;
Using System.Data;
Using System.Web;
Using System.Collections;
Using System.Web.Services;
Using System.Web.Services.Protocols;
Using System.ComponentModel;
Namespace WebService
{
///<summary>
///Service1 Summary Description
///</summary>
[WebService (Namespace = "http://www.jb51.net/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ ToolboxItem (false)]
public class Service1:System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld ()
{
Return to "Hello World";
}
[WebMethod]
public string SayHello (string name)
{
Return "Hello" +name;
}
}
}
Header file
[Code]
#pragma once
#include "stdafx.h"
#include "Atlbase.h"
#import "Msxml.dll"
#import "Msxml4.dll"
using namespace MSXML2;
#include <string>
#include <iostream>
using namespace Std;
Calling code
Copy Code code as follows:
#include "Main.h"
int main (int argc, char* argv[])
{
printf ("Test of XMLHTTP by masterz!\n");
CoInitialize (NULL);
Try
{
Ixmlhttprequestptr xmlrequest;//define HTTP request objects
XMLRequest. CreateInstance (__uuidof (XMLHTTP));//Create real column
CComVariant Vfalse (FALSE);
CComVariant Vnull (NULL);
Xmlrequest->open ("POST", bstr_t ("http://192.168.71.172/Service1.asmx?wsdl"), vfalse,vnull,vnull); Open the Webserveice method: Add? wsdl
Xmlrequest->setrequestheader (_bstr_t (_t ("Content-type")), _bstr_t (_t ("Text/xml"));
String sb;
Sb.append ("<?xml version= ' 1.0 ' encoding= ' utf-8 '?> ')";
Sb.append ("<soapenv:envelope xmlns:soapenv= ' http://www.jb51.net/soap/envelope/' xmlns:tem= ' http://www.jb51.net/' >");
Sb.append ("<soapenv:Header/>");
Sb.append ("<soapenv:Body>");
Sb.append ("<tem:HelloWorld/>");//Call HelloWorld function
Sb.append ("<tem:SayHello>");
Sb.append ("<tem:name>colin</tem:name>");//Call SayHello function, parameter name is name, value is Colin
Sb.append ("</tem:SayHello>");
Sb.append ("</soapenv:Body>");
Sb.append ("</soapenv:Envelope>");
Xmlrequest->send (_variant_t (Sb.c_str ()))//Send data
BSTR Bstrbody;
Xmlrequest->get_responsetext (&bstrbody);/Get Return Data
_bstr_t bstrtbody (bstrbody);
printf ("%s\n", (LPCTSTR) bstrtbody);
msxml2::ixmldomdocument2ptr M_xmldoc;
M_xmldoc. CreateInstance (__uuidof (MSXML2::D omdocument));
M_xmldoc->loadxml (bstrbody);
msxml2::ixmldomnodeptr node = m_xmldoc->documentelement-> FirstChild;
LPCTSTR str = (LPCTSTR) node->nodename;
String str2= (String) m_xmldoc->documentelement->text;
cout<<str2<<endl;
}
catch (_com_error &e)
{
printf ("Description = '%s ' \ n", (char*) e.description ());
}
CoUninitialize ();
printf ("program end\n");
return 0;
}