SOAP Client access to Web service problem
Muralidhar Bojja <[email protected]> Thu, 13 May 2004 12:05:19 -0400
| Newsgroups | gmane.comp.windows.devel.soap.general |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
Hi,
I would like to map the following Java code to C++.
I made an attempt to succeed with MS SOAP Toolkit 2.0, but I could not find
where is the mistake.
It does not matter to me, whether the solution uses SOAP message or not(just
uses stream). I just want to work with the web service with the given
parameters.
For instance, the below given java code just works fine without any soap
message, rather with a stream.
Any solutions or suggestions are appreciated.
----------- Java Code --------------
import java.net.*;
import java.io.*;
public class CrakFrame {
public static void main(String arg[]) {
try {
URL url = new URL("xyz");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new
PrintWriter(connection.getOutputStream());
out.print("Petition");
out.print("=");
out.print("<AvailableColours><Colour>Red</Colour></AvailableColours>");
out.close();
BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
boolean more = true;
while(more) {
String line = in.readLine();
if(line == null) more = false;
else System.out.println(line);
}
}catch (IOException e) {e.printStackTrace();}
}
}
----------- Visual C++ code ------------------
#include <stdio.h>
#include <fstream.h>
#include <stdlib.h> // for exit()
#import "msxml3.dll"
using namespace MSXML2;
#import "D:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll" \
exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib;
int main (void)
{
CoInitialize(NULL);
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service
Connector.CreateInstance(__uuidof(HttpConnector));
Connector->Property["EndPointURL"] =
"http://213.170.46.114:8004/Service1.asmx?op=FurnitureDB";
Connector->Connect();
// Begin message
Connector->Property["SoapAction"] = "http://www.indra.es/FurnitureDB";
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("Petition","http://www.indra.es/FurnitureDB","","");
Serializer->startElement("AvailableColours","","","");
Serializer->startElement("Colour","","","");
Serializer->writeString("Red");
Serializer->endElement();
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));
// Connect 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);
// Close the Service
CoUninitialize();
return 0;
}
--
Bojja