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

Discussion in 'ASP .Net Web Services' started by Tony C, Jul 17, 2003.

  1. Tony C

    Tony C Guest

    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
     
    Tony C, Jul 17, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Dino Chiesa [MSFT], Jul 19, 2003
    #2
    1. Advertising

  3. 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
    >.
    >
     
    Xiangyang Liu, Jul 20, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sham Ramakrishnan
    Replies:
    2
    Views:
    8,475
    Sham Ramakrishnan
    Jul 1, 2003
  2. Nick Chan
    Replies:
    0
    Views:
    524
    Nick Chan
    Sep 13, 2007
  3. Jim Griffiths

    Using .NET web service with SOAP Toolkit 3

    Jim Griffiths, Oct 9, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    175
    Jim Griffiths
    Oct 9, 2003
  4. Prabhu

    .net SOAP toolkit performance for SOAP deserialization

    Prabhu, Nov 12, 2004, in forum: ASP .Net Web Services
    Replies:
    5
    Views:
    315
    Dan Rogers
    Nov 18, 2004
  5. Curt K
    Replies:
    3
    Views:
    485
    John Saunders [MVP]
    Jun 15, 2007
Loading...

Share This Page