Consuming an ASP .NET Web Service using the MS SOAP Toolkit v3.0

T

Tony C

Hi all I think I am going to go mad if I cant solve this problem.
Basically I have created a simple .NET Web Service that takes a string
as a parameter as follows.

<WebMethod()> _
Public Function ReturnString(ByVal INPUT As String) as String
Return "You passed in:" & INPUT
End Function

Then I created a simple console Application that uses the SOAP toolkit
ot call it as follows

#include "stdafx.h"
#include <stdio.h>
#include "atlbase.h"

#import <msxml4.dll>
using namespace MSXML2;

#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream",
"_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;

void ReturnInput();

int main(int argc, char* argv[])
{
// Initialise COM and call our Web Service Method
CoInitialize(NULL);
ReturnInput();
CoUninitialize();
return 0;
}

void ReturnInput()
{
// SOAP handles for HTTP GET
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
HRESULT hr = S_OK;

// 1) Create a HTTP connector object, set a reference to the WSDL
contract and connect
hr = Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property[_T("EndPointURL")] =
_T("http://localhost/Test/TestSOAP.asmx?WSDL");
hr = Connector->Connect();

// 2) Set the SOAP action and create an instance of the SOAP
serialiser class
Connector->Property[_T("SoapAction")] =
_T("http://tempuri.org/Test/TestSOAP/ReturnString");
hr = Connector->BeginMessage();
hr = Serializer.CreateInstance(__uuidof(SoapSerializer30));
hr = Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

// 3) Build up the actual SOAP XML message for the Web Service to
match the WSDL file
// (N.B. See the test page for the service which shows you the SOAP
Request to build)
hr = Serializer->StartEnvelope(_T("soap"),_T("NONE"),_T(""));
hr = Serializer->StartBody(_T(""));
hr = Serializer->StartElement(_T("ReturnString"),_T("http://localhost/Test/TestSOAP/"),
_T("NONE"),_T(""));
//Parameter
hr = Serializer->StartElement(_T("INPUT"),_T(""),
_T("NONE"),_T(""));
hr = Serializer->WriteString("SomeTest Input");
hr = Serializer->EndElement();
hr = Serializer->EndElement();
hr = Serializer->EndBody();
hr = Serializer->EndEnvelope();
hr = Connector->EndMessage();

// 4) Create an instance of the SOAP reader class, and load the
resulting
// stream that is returned into an XMLDom object
hr = Reader.CreateInstance(__uuidof(SoapReader30));
hr = Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),
_T(""));
CComQIPtr<IXMLDOMDocument2> spResponseXMLDOM;
spResponseXMLDOM = Reader->Dom;

// 5) Print the SOAP repsonse out the console, but we have an XMLDOM
object
// at this point thatwe can manipulate and traverse using the
methods
USES_CONVERSION;
printf(_T("Response: %s\n"), (const
char*)W2A(spResponseXMLDOM->xml));
printf(_T("\n\nPress Enter to continue..."));
getchar();
}

The problem is that the parameters are not getting passed to the .NET
Web Service at all, and i am really confused as to why?

Any ideas would be greatly appreciated

Operating System: Windows XP (SP1)
Development Tool: Microsoft Visual Studio .NET 2003 Enterprise
Architect
SOAP Toolkit: Microsoft SOAP Toolkit v3.0
 
D

Dino Chiesa [MSFT]

did you use the SOAP Trace tool (included with MS SOAP toolkit) and if so,
what did it say?

There is also a proxy trace tool which is nice - google for proxytrace.


Tony C said:
Hi all I think I am going to go mad if I cant solve this problem.
Basically I have created a simple .NET Web Service that takes a string
as a parameter as follows.

<WebMethod()> _
Public Function ReturnString(ByVal INPUT As String) as String
Return "You passed in:" & INPUT
End Function

Then I created a simple console Application that uses the SOAP toolkit
ot call it as follows

#include "stdafx.h"
#include <stdio.h>
#include "atlbase.h"

#import <msxml4.dll>
using namespace MSXML2;

#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream",
"_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;

void ReturnInput();

int main(int argc, char* argv[])
{
// Initialise COM and call our Web Service Method
CoInitialize(NULL);
ReturnInput();
CoUninitialize();
return 0;
}

void ReturnInput()
{
// SOAP handles for HTTP GET
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
HRESULT hr = S_OK;

// 1) Create a HTTP connector object, set a reference to the WSDL
contract and connect
hr = Connector.CreateInstance(__uuidof(HttpConnector30));
Connector->Property[_T("EndPointURL")] =
_T("http://localhost/Test/TestSOAP.asmx?WSDL");
hr = Connector->Connect();

// 2) Set the SOAP action and create an instance of the SOAP
serialiser class
Connector->Property[_T("SoapAction")] =
_T("http://tempuri.org/Test/TestSOAP/ReturnString");
hr = Connector->BeginMessage();
hr = Serializer.CreateInstance(__uuidof(SoapSerializer30));
hr = Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

// 3) Build up the actual SOAP XML message for the Web Service to
match the WSDL file
// (N.B. See the test page for the service which shows you the SOAP
Request to build)
hr = Serializer->StartEnvelope(_T("soap"),_T("NONE"),_T(""));
hr = Serializer->StartBody(_T(""));
hr = Serializer->StartElement(_T("ReturnString"),_T("http://localhost/Test/TestSO
AP/"),
_T("NONE"),_T(""));
//Parameter
hr = Serializer->StartElement(_T("INPUT"),_T(""),
_T("NONE"),_T(""));
hr = Serializer->WriteString("SomeTest Input");
hr = Serializer->EndElement();
hr = Serializer->EndElement();
hr = Serializer->EndBody();
hr = Serializer->EndEnvelope();
hr = Connector->EndMessage();

// 4) Create an instance of the SOAP reader class, and load the
resulting
// stream that is returned into an XMLDom object
hr = Reader.CreateInstance(__uuidof(SoapReader30));
hr = Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),
_T(""));
CComQIPtr<IXMLDOMDocument2> spResponseXMLDOM;
spResponseXMLDOM = Reader->Dom;

// 5) Print the SOAP repsonse out the console, but we have an XMLDOM
object
// at this point thatwe can manipulate and traverse using the
methods
USES_CONVERSION;
printf(_T("Response: %s\n"), (const
char*)W2A(spResponseXMLDOM->xml));
printf(_T("\n\nPress Enter to continue..."));
getchar();
}

The problem is that the parameters are not getting passed to the .NET
Web Service at all, and i am really confused as to why?

Any ideas would be greatly appreciated

Operating System: Windows XP (SP1)
Development Tool: Microsoft Visual Studio .NET 2003 Enterprise
Architect
SOAP Toolkit: Microsoft SOAP Toolkit v3.0
 
X

Xiangyang Liu

Since you are using Microsoft Soap Toolkit, you might
want to consider using the "SoapClient" object instead of
other low level objects in the tool kit.

Using the SoapClient there are only three simple steps
when calling a web method, 1) Create the SoapClient
object, 2) Initialize the object with the web service
URL, 3) Invoke the web method by name.

You may think that SoapClient is only for VB programs,
however I wrote a com component XYSoapClient.dll which
changed that. This com component can be easily used in
VB, C++, and .NET applications. Please refer to my
CodeProject article "Invoking web methods from a C++
console application"
(http://www.codeproject.com/com/XYSoapClient.asp) for
details.

You will find that calling a web service is a lot easier
this way.

Good luck.


-----Original Message-----
Hi all I think I am going to go mad if I cant solve this problem.
Basically I have created a simple .NET Web Service that takes a string
as a parameter as follows.

<WebMethod()> _
Public Function ReturnString(ByVal INPUT As String) as String
Return "You passed in:" & INPUT
End Function

Then I created a simple console Application that uses the SOAP toolkit
ot call it as follows

#include "stdafx.h"
#include <stdio.h>
#include "atlbase.h"

#import <msxml4.dll>
using namespace MSXML2;

#import "C:\Program Files\Common
Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream",
"_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;

void ReturnInput();

int main(int argc, char* argv[])
{
// Initialise COM and call our Web Service Method
CoInitialize(NULL);
ReturnInput();
CoUninitialize();
return 0;
}

void ReturnInput()
{
// SOAP handles for HTTP GET
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
HRESULT hr = S_OK;

// 1) Create a HTTP connector object, set a reference to the WSDL
contract and connect
hr = Connector.CreateInstance(__uuidof (HttpConnector30));
Connector->Property[_T("EndPointURL")] =
_T("http://localhost/Test/TestSOAP.asmx?WSDL");
hr = Connector->Connect();

// 2) Set the SOAP action and create an instance of the SOAP
serialiser class
Connector->Property[_T("SoapAction")] =
_T("http://tempuri.org/Test/TestSOAP/ReturnString");
hr = Connector->BeginMessage();
hr = Serializer.CreateInstance(__uuidof (SoapSerializer30));
hr = Serializer->Init(_variant_t((IUnknown*) Connector->InputStream));

// 3) Build up the actual SOAP XML message for the Web Service to
match the WSDL file
// (N.B. See the test page for the service which shows you the SOAP
Request to build)
hr = Serializer->StartEnvelope(_T("soap"),_T ("NONE"),_T(""));
hr = Serializer->StartBody(_T(""));
hr = Serializer->StartElement(_T ("ReturnString"),_T("http://localhost/Test/TestSOAP/"),
_T("NONE"),_T(""));
//Parameter
hr = Serializer-
StartElement(_T("INPUT"),_T(""),
_T("NONE"),_T(""));
hr = Serializer-
WriteString("SomeTest Input");
hr = Serializer-
EndElement();
hr = Serializer->EndElement();
hr = Serializer->EndBody();
hr = Serializer->EndEnvelope();
hr = Connector->EndMessage();

// 4) Create an instance of the SOAP reader class, and load the
resulting
// stream that is returned into an XMLDom object
hr = Reader.CreateInstance(__uuidof (SoapReader30));
hr = Reader->Load(_variant_t((IUnknown*)Connector-
OutputStream),
_T(""));
CComQIPtr<IXMLDOMDocument2> spResponseXMLDOM;
spResponseXMLDOM = Reader->Dom;

// 5) Print the SOAP repsonse out the console, but we have an XMLDOM
object
// at this point thatwe can manipulate and traverse using the
methods
USES_CONVERSION;
printf(_T("Response: %s\n"), (const
char*)W2A(spResponseXMLDOM->xml));
printf(_T("\n\nPress Enter to continue..."));
getchar();
}

The problem is that the parameters are not getting passed to the .NET
Web Service at all, and i am really confused as to why?

Any ideas would be greatly appreciated

Operating System: Windows XP (SP1)
Development Tool: Microsoft Visual Studio .NET 2003 Enterprise
Architect
SOAP Toolkit: Microsoft SOAP Toolkit v3.0
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top