Calling a problem with WebService with SOAP Toolkit

xiaoxiao2021-03-06  22

Problem Description: In the use of non-.NET client calls WebService, it is easy to implement in accordance with the instructions in SOAP Toolkit, but it finds a problem during actual use. If the method provided by WebService is: int SimpleMath.Add (INT N1, INT N2), the return value is N1 N2, but according to the example provided by SOAP Toolkit, use VC to be called, the return value is 0.

Record my resolution process, make a memo.

Test Environment: OS: WindowsXP ProfessionalWebService: VS.NET 2003Webservice Running Environment: IIS client: VC6.0, Vcsoaptoolkit SDK: 3.0 in vs.net

Problem reproduction: Look at the example code after the Toolkit is slightly modified:

#includort #import "msxml4.dll" USING NAMESPACE MSXML2; #import "c: / program files / common files / mssoap / binaries / mssoap30.dll" / exclude ("istream", "IerrorInfo", " ISEQUENTIALSTREAM "," _large_integer ", /" tagstatstg "," _filetime ") Using Namespace MSSOAPLIB30;

INT test2 () {

Isoapserializerptr Serializer; IsoapConnectorptr Connector; // Connect To The Service Connector.createInstance (__ uuidof (httpconnector);

Connector-> Property ["endpointurl"] = "http://localhost/wstest/simplemath.asmx? WSDL"; connector-> connect (); // begin message connection -> proty ["soapaction"] = "http: //tempuri.org/Add "; 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-> Startenvelop (",", ""); serializer-> startbody (""); serializer-> StartElement ("add", "http://tempuri.org/" "" "" "; Serializer-> StartElement (" n1 ",", "," ""); serializer-> WritestRing ("5"); Serializer-> Endelement (); Serializer-> StartElement ("N2", ",", ""); Serializer-> WriteString ("10"); serializer-> endelement (); serializer-> endelement (); serializer-> Endbody (); serializer-> endenvelope (); // send the message to the Web service connector-> endMessage (); // let us read the response reader.createInstance (__ uuidof (soapreader)); // co Nnect The Reader To The Output Stream of the Connector Reader-> Load (_variant_t ((iUnknown *) Connector-> OutputStream), ""); // Display The Result Printf ("Answer:% S / N", (Const Char *) Reader-> rpcResult-> text); return 0;} The return result should be 15, but actually returns 0. Searching Online Search finding that someone proposes to change the parameters of the webservice method to String, then transform in the method, I think this is not a good way. In fact, I have found that this implementation will be more. The return result should be 15, but actually returns 0.

Searching Online Search finding that someone proposes to change the parameters of the webservice method to String, then transform in the method, I think this is not a good way. In fact, I have found that this implementation will be more. Analysis process:

Take a look at the tracking tool MSSoApt in SOAP Toolkit, what data has been sent to WebService in the end:

> 5 10

Take a look at VS.NET debugging, the data issued by the IE browser (template):

int int

Where is the difference? In the data of SOAPToolkit, there is more EncodingStyle properties, although there is no value. We want to block this property. In the parameter in the StarTelement method of SOAPSERIAL30, this property can not be set as follows. The change code is as follows:

... serializer-> StartElement ("add", "http://tempuri.org/", "none", ""); serializer-> StartElement ("N1", "," None "," ") Serializer-> WriteString ("5"); serializer-> endelement (); Serializer-> StartElement ("N2", "," None "," "); Serializer-> WritestRing (" 10 "); Serializer > endelement (); serializer-> endelement (); ... but return results or 0, it seems that ENCODINGSTYLE is not related. Look at the tracking situation:

startelement ("n1", "http://tempuri.org/", "None "," ""); Serializer-> WritestRing ("5"); serializer-> endelement (); serializer-> StartElement ("n2", "http://tempuri.org/", "none", "") Serializer-> WriteString ("10"); serializer-> endelement (); serializer-> endelement ();

The test result is normal, returns 15.

Take a look at XML data from this time: 10 Cause:

I can't summarize who is the problem :(

Perhaps it is VS.NET problem, perhaps the problem of SOAPToolkit, perhaps the example of him, maybe there is a problem, maybe my running environment has problems, of course, more may not really understand the namespace of XML or no Use WebService correctly.

转载请注明原文地址:https://www.9cbs.com/read-43146.html

New Post(0)