<span id="Label3"></p><p><p>1. First install the SOAPTOOLKIT3.0 installation package and install it (my installation directory is: D:\Program files\mssoap\)</p></p><p><p>2. New VC Console program (empty project), project Name: winconsole6invokewebservice, Add a C + + source file (main.cpp), D:\Program The Lib file under the SOAP installation directory Files\mssoap\ Lib\mssoap30.lib copied to the project Folder.</p></p><p><p>3. Add Source Code:</p></p><pre class="brush:cpp;gutter:true;">#include <stdio.h> #include <iostream> #include <vector> #import "msxml4.dll" using namespace std; Using namespace MSXML2; #import "C:\Program Files\Common files\mssoap\binaries\mssoap30.dll" exclude ("IStream", "ierrorinfo", "isequential Stream "," _large_integer "," _ularge_integer "," tagstatstg "," _filetime ") using namespace MSSOAPLib30; void query (char* endpointurl, char* Namespace, char* method, vector<string>& v) {isoapserializerptr Serialize R Isoapreaderptr Reader; Isoapconnectorptr Connector; Connect to the service connector.createinstance (__uuidof (HttpConnector30)); connector->property["endpointurl"] = endpointurl; Interface position Connector->connect (); and server Connection/Begin message connector->property["soapaction"] = _bstr_t (Namespace) + _bstr_t (method); Connector->beginmessage (); Serializer.createinstance (__uuidof (SoapSerializer30)); Will SerializER connected to Connector input string serializer->init (_variant_t ((iunknown*) connector->inputstream)); Create a SOAP message Serializer->startenvelope ("soap", "", ""); Serializer->startbody ("body"); Serializer->startelement (method, Namespace, "", ""); The namespace must have a for (vector<string>::iterator it = v.begin (); it! = v.end (); It++) {serializer->startele ment ("username", Namespace, "", ""); Serializer->writestring (it->c_str ()); Serializer->endelement (); } serializer->endelement (); Serializer->endbody (); Serializer->endenvelope (); Connector->endmessage (); Send the message to the Web service//read response reader.createinstance (__uuidof (SoapReader30)); Reader->load (_variant_t ((iunknown*) connector->outputstream), ""); printf ("Answer:%s\n", (const char*) reader->rpcresult->text); Reader->rpcresult->gettext () equivalent} int main (int argc, char* argv[]) {CoInitialize (NULL); Char* Endpointurl = "http://192.168.0.100/WebService1/Service.asmx"; char* Namespace = "http://tempuri.org/"; Vector<string> v1, v2; V2.push_back ("joeblack"); Query (endpointurl, Namespace, "Hello", v2); CoUninitialize (); GetChar (); Return 0;}</pre><p><p> </p></p>In this way, the program is completed, and can be run to get WebService Service.<p><p>One of the WebService services is developed using asp.net2005 (c #), The source code is as Follows:</p></p><pre class="brush:csharp;gutter:true;">Using system;using system.web;using system.web.services;using System.Web.Services.Protocols; [WebService (Namespace = "http://tempuri.org/")] [webservicebinding (conformsto = Wsiprofiles.basicprofile1_1)]public class service:system.web.services.webservice{ Public Service () {//if using a design component, uncomment the following line//initializecomponent (); } [WebMethod (Description = "let's say \" hi\ "")] public string Hi () {return "Hello world, Happy New year! "; } [WebMethod (Description = "hello joeblack")] public string Hello (string Username) {return username + ", Happy New year! ";} [WebMethod (Description = "method of summation")] public double addition (double i, double j) {return i + j; } [WebMethod (Description = "method of difference")] public double subtract (double i, double j) {return i-j; } [WebMethod (Description = "method of quadrature")] public double multiply (double i, double j) {return i * j; } [WebMethod (Description = "operator'sMethod ")] Public Double Division (double i, double j) {if (j! = 0) return i/j; else return 0; }}</pre><p><p> </p></p><span style="font-size: 14px; line-height: 1.5; background-color: #ffffff;"><span style="font-size: 14px; line-height: 1.5; background-color: #ffffff;">Call the Hello method, which is called as Follows:</span></span>SOAP 1.1<p><p>The following is an example of a SOAP 1.2 request and Response. The placeholder displayed is replaced with the <span class="value">actual Value. </span></p></p><pre><pre><span class="value">Lengthsoapaction: "http://tempuri.org/Hello" <?xml version= "1.0" encoding= "utf-8"? ><soap:envelope xmlns: xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/XMLSchema" xmlns:soap= "http// schemas.xmlsoap.org/soap/envelope/"> <soap:Body>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.