Consuming Web Service using classis ASP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mo

    Consuming Web Service using classis ASP

    Hi,

    I can not find a decent example showing how to consume a asp.net 2.0
    web service using classic ASP. Does any body have an example I could
    use?

    Thanks

  • Bob Barrows [MVP]

    #2
    Re: Consuming Web Service using classis ASP

    Mo wrote:
    Hi,
    >
    I can not find a decent example showing how to consume a asp.net 2.0
    web service using classic ASP. Does any body have an example I could
    use?
    >
    It's not something a lot of us do. All I can suggest is a google search.
    I seem to remember 4GuysFromRolla had a good article about it.



    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Comment

    • Jon Paal [MSMD]

      #3
      Re: Consuming Web Service using classis ASP




      "Mo" <le_mo_mo@yahoo .comwrote in message news:1180986162 .292609.197400@ m36g2000hse.goo glegroups.com.. .
      Hi,
      >
      I can not find a decent example showing how to consume a asp.net 2.0
      web service using classic ASP. Does any body have an example I could
      use?
      >
      Thanks
      >

      Comment

      • Mo

        #4
        Re: Consuming Web Service using classis ASP

        Thank you all for your great posts. I have created a simple helloworld
        service which I am trying to call from ASP. I am using the following
        code which is posted in one of the sites I found.:

        html>
        <head>
        <title>Callin g a webservice from classic ASP</title>
        </head>
        <body>
        <%
        If Request.ServerV ariables("REQUE ST_METHOD") = "POST" Then
        Dim xmlhttp
        Dim DataToSend
        DataToSend="par am1="&Request.F orm("text1")
        Dim postUrl
        postUrl = " http://xxxlon.xxxmo.com/AWS.asmx/TestService HTTP/1.1"
        Set xmlhttp = server.Createob ject("MSXML2.XM LHTTP")
        xmlhttp.Open "POST",postUrl, false
        xmlhttp.setRequ estHeader "Content-Type", _
        "applicatio n/x-www-form- urlencoded"
        xmlhttp.send DataToSend
        Response.Write( xmlhttp.respons eText)
        End If
        %>
        <FORM method=POST name="form1">
        Enter the two Values to be Added<BR>
        <INPUT type="text" name="text1">

        <BR><BR>
        <INPUT type="submit" value="Add" name="submit1">
        </form>
        </body>
        </html></PRE>

        But when I access the page I am getting the following error:


        Request format is unrecognized for URL unexpectedly ending in '/
        TestService'.
        Description: An unhandled exception occurred during the execution of
        the current web request. Please review the stack trace for more
        information about the error and where it originated in the code.

        Exception Details: System.InvalidO perationExcepti on: Request format is
        unrecognized for URL unexpectedly ending in '/TestService'.


        If I remove the /TestService from the service url I get the following
        error after I submit the form:

        soap:ReceiverSy stem.Web.Servic es.Protocols.So apException: Server was
        unable to process request. ---System.Xml.XmlE xception: Data at the
        root level is invalid. Line 1, position 1.
        at System.Xml.XmlT extReaderImpl.T hrow(Exception e)
        at System.Xml.XmlT extReaderImpl.T hrow(String res, String arg)
        at System.Xml.XmlT extReaderImpl.P arseRootLevelWh itespace()
        at System.Xml.XmlT extReaderImpl.P arseDocumentCon tent()
        at System.Xml.XmlT extReaderImpl.R ead()
        at System.Xml.XmlT extReader.Read( )
        at
        System.Web.Serv ices.Protocols. SoapServerProto col.SoapEnvelop eReader.Read()
        at System.Xml.XmlR eader.MoveToCon tent()
        at
        System.Web.Serv ices.Protocols. SoapServerProto col.SoapEnvelop eReader.MoveToC ontent()
        at
        System.Web.Serv ices.Protocols. SoapServerProto colHelper.GetRe questElement()
        at
        System.Web.Serv ices.Protocols. Soap12ServerPro tocolHelper.Rou teRequest()
        at
        System.Web.Serv ices.Protocols. SoapServerProto col.RouteReques t(SoapServerMes sage
        message)
        at System.Web.Serv ices.Protocols. SoapServerProto col.Initialize( )
        at System.Web.Serv ices.Protocols. ServerProtocolF actory.Create(T ype
        type, HttpContext context, HttpRequest request, HttpResponse response,
        Boolean& abortProcessing )
        --- End of inner exception stack trace ---


        What am I doing wrong?

        Thanks

        Comment

        • Dave Anderson

          #5
          Re: Consuming Web Service using classis ASP

          "Mo" wrote:
          Set xmlhttp = server.Createob ject("MSXML2.XM LHTTP")
          >
          ...What am I doing wrong?
          I know this does not address your initial problem, but you have created the
          potential for more by using the MSXML2.XMLHTTP object when you ought to use
          the server-safe MSXML2.ServerXM LHTTP.





          --
          Dave Anderson

          Unsolicited commercial email will be read at a cost of $500 per message. Use
          of this email address implies consent to these terms.

          Comment

          • Jon Paal [MSMD]

            #6
            Re: Consuming Web Service using classis ASP

            looks like a problem with the posturl

            try removing "HTTP/1.1"


            "Mo" <le_mo_mo@yahoo .comwrote in message news:1181008537 .890174.228220@ o5g2000hsb.goog legroups.com...
            Thank you all for your great posts. I have created a simple helloworld
            service which I am trying to call from ASP. I am using the following
            code which is posted in one of the sites I found.:
            >
            html>
            <head>
            <title>Callin g a webservice from classic ASP</title>
            </head>
            <body>
            <%
            If Request.ServerV ariables("REQUE ST_METHOD") = "POST" Then
            Dim xmlhttp
            Dim DataToSend
            DataToSend="par am1="&Request.F orm("text1")
            Dim postUrl
            postUrl = " http://xxxlon.xxxmo.com/AWS.asmx/TestService HTTP/1.1"
            Set xmlhttp = server.Createob ject("MSXML2.XM LHTTP")
            xmlhttp.Open "POST",postUrl, false
            xmlhttp.setRequ estHeader "Content-Type", _
            "applicatio n/x-www-form- urlencoded"
            xmlhttp.send DataToSend
            Response.Write( xmlhttp.respons eText)
            End If
            %>
            <FORM method=POST name="form1">
            Enter the two Values to be Added<BR>
            <INPUT type="text" name="text1">
            >
            <BR><BR>
            <INPUT type="submit" value="Add" name="submit1">
            </form>
            </body>
            </html></PRE>
            >
            But when I access the page I am getting the following error:
            >
            >
            Request format is unrecognized for URL unexpectedly ending in '/
            TestService'.
            Description: An unhandled exception occurred during the execution of
            the current web request. Please review the stack trace for more
            information about the error and where it originated in the code.
            >
            Exception Details: System.InvalidO perationExcepti on: Request format is
            unrecognized for URL unexpectedly ending in '/TestService'.
            >
            >
            If I remove the /TestService from the service url I get the following
            error after I submit the form:
            >
            soap:ReceiverSy stem.Web.Servic es.Protocols.So apException: Server was
            unable to process request. ---System.Xml.XmlE xception: Data at the
            root level is invalid. Line 1, position 1.
            at System.Xml.XmlT extReaderImpl.T hrow(Exception e)
            at System.Xml.XmlT extReaderImpl.T hrow(String res, String arg)
            at System.Xml.XmlT extReaderImpl.P arseRootLevelWh itespace()
            at System.Xml.XmlT extReaderImpl.P arseDocumentCon tent()
            at System.Xml.XmlT extReaderImpl.R ead()
            at System.Xml.XmlT extReader.Read( )
            at
            System.Web.Serv ices.Protocols. SoapServerProto col.SoapEnvelop eReader.Read()
            at System.Xml.XmlR eader.MoveToCon tent()
            at
            System.Web.Serv ices.Protocols. SoapServerProto col.SoapEnvelop eReader.MoveToC ontent()
            at
            System.Web.Serv ices.Protocols. SoapServerProto colHelper.GetRe questElement()
            at
            System.Web.Serv ices.Protocols. Soap12ServerPro tocolHelper.Rou teRequest()
            at
            System.Web.Serv ices.Protocols. SoapServerProto col.RouteReques t(SoapServerMes sage
            message)
            at System.Web.Serv ices.Protocols. SoapServerProto col.Initialize( )
            at System.Web.Serv ices.Protocols. ServerProtocolF actory.Create(T ype
            type, HttpContext context, HttpRequest request, HttpResponse response,
            Boolean& abortProcessing )
            --- End of inner exception stack trace ---
            >
            >
            What am I doing wrong?
            >
            Thanks
            >

            Comment

            • Mo

              #7
              Re: Consuming Web Service using classis ASP

              Thank you for all your great posts. I am still haven't been able to
              get it to work. After I change the object to MSXML2.ServerXM LHTTP I
              am getting 500 error on the browser after the button click. I also
              tried removeing http/1.1 from the desciprion of the service and I get
              the error saying that unexpected ending in /TestService.

              Any other recommendations ? There must be a working code somewhere. I
              do not believe I am the first guy looking for this.

              Thanks

              Comment

              • Adeel Taseer

                #8
                Consuming Web Service using Classic ASP

                I am getting the same problem. A web service can be accessed if both web service and ASP page are on the same server, but if we change it to different servers then it's not returning any response XML. What problem could have been in this I am using MSXML2.ServerXM LHTTP to retrieve XML.

                Thanks

                Comment

                • Dave Anderson

                  #9
                  Re: Consuming Web Service using Classic ASP

                  "Adeel Taseer" wrote:
                  I am getting the same problem.
                  Same problem as what?

                  A web service can be accessed if both web service and ASP page are
                  on the same server, but if we change it to different servers then
                  it's not returning any response XML.
                  Are there any IP restrictions on the service you are attempting to consume?
                  What kind of response do you get if you consume the service directly with a
                  web browser (while logged onto the server that consumes the service) ?

                  Is the service on the remote server an ASP.NET Web Service? If so, have you
                  tried toggling this?




                  --
                  Dave Anderson

                  Unsolicited commercial email will be read at a cost of $500 per message. Use
                  of this email address implies consent to these terms.

                  Comment

                  Working...