Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Consuming an ASP .NET Web Service using the MS SOAP Toolkit v3.0

Reply
Thread Tools

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

 
 
Tony C
Guest
Posts: n/a
 
      07-17-2003
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(SoapSerializer3 0));
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
 
Reply With Quote
 
 
 
 
Dino Chiesa [MSFT]
Guest
Posts: n/a
 
      07-18-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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(SoapSerializer3 0));
> 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



 
Reply With Quote
 
 
 
 
Xiangyang Liu
Guest
Posts: n/a
 
      07-20-2003
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
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
consuming web service with SOAP toolkit in sql server 2005 Nick Chan ASP .Net 0 09-13-2007 09:48 AM
SOAP Header in a Dot Net 2.0 Web Service Client Consuming a WCF 3.0 service. Curt K ASP .Net Web Services 3 06-15-2007 10:19 PM
ASP web service with ssl in soap toolkit 3 problem hanz ASP .Net Web Services 0 04-27-2005 11:08 AM
Using .NET web service with SOAP Toolkit 3 Jim Griffiths ASP .Net Web Services 0 10-09-2003 11:28 AM
SOAP Client creation in ASP.NET using MS SOAP Toolkit Sham Ramakrishnan ASP .Net 2 07-01-2003 11:29 AM



Advertisments