How to have an ASP page use a web service?

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

    How to have an ASP page use a web service?

    Hello,

    I have created a web service that will return SQL Server's Northwind
    productid quantity.

    If i access my web service from the Internet, i type the following:



    then i click on one of the web services there, for example GetInventory



    i get a text field where i enter the ProductID, press a command button and i
    get the quantity of that ProductID.


    Now, if i type the following at the address link :



    i get the result also.

    Now, my problem is I don't know how i can call this web service using an ASP
    page. My goal is to use
    another website to send a parameter to this web service and get the result
    back, display the result on the html page for
    the user and also insert the value in a SQL Server table.

    Can someone please help me out? I need a sample code on how to write ASP
    code to pass a value to a web
    service residing on another server, get the result and display it on the
    HTML page.


    I would appreciate any help.

    Thank you


  • Aaron Bertrand - MVP

    #2
    Re: How to have an ASP page use a web service?



    --
    Aaron Bertrand
    SQL Server MVP
    Please contact this domain's administrator as their DNS Made Easy services have expired.





    "serge" <sergea@nospam. ehmail.com> wrote in message
    news:Nuqsc.1650 8$sr3.315197@ne ws20.bellglobal .com...[color=blue]
    > Hello,
    >
    > I have created a web service that will return SQL Server's Northwind
    > productid quantity.
    >
    > If i access my web service from the Internet, i type the following:
    >
    > http://www.mydomainnametest.com/nort...inventory.asmx
    >
    > then i click on one of the web services there, for example GetInventory
    >
    > http://www.mydomainnametest.com/nort...p=GetInventory
    >
    > i get a text field where i enter the ProductID, press a command button and[/color]
    i[color=blue]
    > get the quantity of that ProductID.
    >
    >
    > Now, if i type the following at the address link :
    >
    >[/color]
    http://www.mydomainnametest.com/nort...ry?ProductID=2[color=blue]
    >
    > i get the result also.
    >
    > Now, my problem is I don't know how i can call this web service using an[/color]
    ASP[color=blue]
    > page. My goal is to use
    > another website to send a parameter to this web service and get the result
    > back, display the result on the html page for
    > the user and also insert the value in a SQL Server table.
    >
    > Can someone please help me out? I need a sample code on how to write ASP
    > code to pass a value to a web
    > service residing on another server, get the result and display it on the
    > HTML page.
    >
    >
    > I would appreciate any help.
    >
    > Thank you
    >
    >[/color]


    Comment

    • serge

      #3
      Re: How to have an ASP page use a web service?

      Thanks Aaron, that helped a lot.

      This is the code of my test.asp located on my Inetpub/wwwroot folder

      <%
      url =
      "http://www.mydomaintes t.com/northwind2/inventory.asmx/GetInventory?pr oducti
      d=24"
      set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
      on error resume next
      xmlhttp.open "GET", url, false
      xmlhttp.send ""
      if err.number <> 0 then
      response.write "Url not found"
      else
      response.write xmlhttp.respons eText
      end if
      set xmlhttp = nothing
      %>

      When i run http://localhost/test.asp

      this is the result i get

      <?xml version="1.0" encoding="utf-8" ?>
      <int xmlns="http://www.mydomaintes t.com/Northwind2/Service1">61</int>


      I I don't understand why sometimes when i run the same page after saving the
      test.asp page
      or deleting cookies, closing browser, doing all kinds of things... no idea
      what i do/change, but
      i get the result:

      61

      Only 61 gets printed on the page, but sometimes the same page no longer
      prints 61, it prints the whole XML text again!


      So, how i can simply retrieve only the value 61 and put it in a variable
      and then print only the value of
      the variable, instead of the whole XML string?

      Anyone?

      Thank you



      Comment

      • Aaron Bertrand - MVP

        #4
        Re: How to have an ASP page use a web service?

        You'd have to parse it, probably using RegExp would be your best bet.

        (Chris Hohmann is the resident RegExpert around here...)

        --
        Aaron Bertrand
        SQL Server MVP
        Please contact this domain's administrator as their DNS Made Easy services have expired.





        "serge" <sergea@nospam. ehmail.com> wrote in message
        news:Bcssc.2103 2$tb4.630871@ne ws20.bellglobal .com...[color=blue]
        > Thanks Aaron, that helped a lot.
        >
        > This is the code of my test.asp located on my Inetpub/wwwroot folder
        >
        > <%
        > url =
        >[/color]
        "http://www.mydomaintes t.com/northwind2/inventory.asmx/GetInventory?pr oducti[color=blue]
        > d=24"
        > set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
        > on error resume next
        > xmlhttp.open "GET", url, false
        > xmlhttp.send ""
        > if err.number <> 0 then
        > response.write "Url not found"
        > else
        > response.write xmlhttp.respons eText
        > end if
        > set xmlhttp = nothing
        > %>
        >
        > When i run http://localhost/test.asp
        >
        > this is the result i get
        >
        > <?xml version="1.0" encoding="utf-8" ?>
        > <int xmlns="http://www.mydomaintes t.com/Northwind2/Service1">61</int>
        >
        >
        > I I don't understand why sometimes when i run the same page after saving[/color]
        the[color=blue]
        > test.asp page
        > or deleting cookies, closing browser, doing all kinds of things... no[/color]
        idea[color=blue]
        > what i do/change, but
        > i get the result:
        >
        > 61
        >
        > Only 61 gets printed on the page, but sometimes the same page no longer
        > prints 61, it prints the whole XML text again!
        >
        >
        > So, how i can simply retrieve only the value 61 and put it in a variable
        > and then print only the value of
        > the variable, instead of the whole XML string?
        >
        > Anyone?
        >
        > Thank you
        >
        >
        >[/color]


        Comment

        • Chris Hohmann

          #5
          Re: How to have an ASP page use a web service?

          "Aaron Bertrand - MVP" <aaron@TRASHasp faq.com> wrote in message
          news:eWImancQEH A.2704@TK2MSFTN GP10.phx.gbl...[color=blue]
          > "serge" <sergea@nospam. ehmail.com> wrote in message
          > news:Bcssc.2103 2$tb4.630871@ne ws20.bellglobal .com...[color=green]
          > > Thanks Aaron, that helped a lot.
          > >
          > > This is the code of my test.asp located on my Inetpub/wwwroot folder
          > >
          > > <%
          > > url =
          > >[/color]
          >[/color]
          "http://www.mydomaintes t.com/northwind2/inventory.asmx/GetInventory?pr oducti[color=blue][color=green]
          > > d=24"
          > > set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
          > > on error resume next
          > > xmlhttp.open "GET", url, false
          > > xmlhttp.send ""
          > > if err.number <> 0 then
          > > response.write "Url not found"
          > > else
          > > response.write xmlhttp.respons eText
          > > end if
          > > set xmlhttp = nothing
          > > %>
          > >
          > > When i run http://localhost/test.asp
          > >
          > > this is the result i get
          > >
          > > <?xml version="1.0" encoding="utf-8" ?>
          > > <int xmlns="http://www.mydomaintes t.com/Northwind2/Service1">61</int>
          > >
          > >
          > > I I don't understand why sometimes when i run the same page after saving[/color]
          > the[color=green]
          > > test.asp page
          > > or deleting cookies, closing browser, doing all kinds of things... no[/color]
          > idea[color=green]
          > > what i do/change, but
          > > i get the result:
          > >
          > > 61
          > >
          > > Only 61 gets printed on the page, but sometimes the same page no[/color][/color]
          longer[color=blue][color=green]
          > > prints 61, it prints the whole XML text again!
          > >
          > >
          > > So, how i can simply retrieve only the value 61 and put it in a[/color][/color]
          variable[color=blue][color=green]
          > > and then print only the value of
          > > the variable, instead of the whole XML string?
          > >
          > > Anyone?
          > >
          > > Thank you
          > >
          > >
          > >[/color]
          > You'd have to parse it, probably using RegExp would be your best bet.
          >
          > (Chris Hohmann is the resident RegExpert around here...)
          >
          > --
          > Aaron Bertrand
          > SQL Server MVP
          > http://www.aspfaq.com/
          >[/color]

          No need for RE's in this scenario. Use Response.Conten tType to explicitly
          declare the type of data being returned to the browser, i.e. XML, HTML,
          plain text, etc... If that does not resolve the ambiguity, please post back
          here.

          -Chris Hohmann
          P.S. "RegExpert" ... lol! :)


          Comment

          • serge

            #6
            Re: How to have an ASP page use a web service?

            Actually, i added the line

            Response.Conten tType = "text/xml"
            before the
            Response.Write xmlhttp.respons eText

            However, i don't think i know what else to do.
            How can i simply retrieve the value from this XML string :

            <?xml version="1.0" encoding="utf-8" ?>
            <int xmlns="http://www.mydomaintes t.com/Northwind2/Service1">61</int>

            All i need is to put the value 61 in a variable in the ASP page.

            Is the only way to get it is to read the whole string and disect the part
            that interests me?

            By the way, the whole ASP code here, does it have anything to do with SOAP?
            If not, does using SOAP give me from freedom to access the result?


            Thank you for your help Chris.



            [color=blue]
            > No need for RE's in this scenario. Use Response.Conten tType to explicitly
            > declare the type of data being returned to the browser, i.e. XML, HTML,
            > plain text, etc... If that does not resolve the ambiguity, please post[/color]
            back[color=blue]
            > here.[/color]


            Comment

            • Bob Barrows [MVP]

              #7
              Re: How to have an ASP page use a web service?

              serge wrote:[color=blue]
              > Actually, i added the line
              >
              > Response.Conten tType = "text/xml"
              > before the
              > Response.Write xmlhttp.respons eText
              >
              > However, i don't think i know what else to do.
              > How can i simply retrieve the value from this XML string :
              >
              > <?xml version="1.0" encoding="utf-8" ?>
              > <int
              > xmlns="http://www.mydomaintes t.com/Northwind2/Service1">61</int>
              >
              > All i need is to put the value 61 in a variable in the ASP page.
              >[/color]

              Use an xml document.
              After the Send statement:

              Set xmldoc = xmlhttp.respons eXML
              thevalue = xmldoc.document Element.text
              response.write thevalue

              Bob Barrows

              --
              Microsoft MVP - ASP/ASP.NET
              Please reply to the newsgroup. This email account is my spam trap so I
              don't check it very often. If you must reply off-line, then remove the
              "NO SPAM"


              Comment

              • serge

                #8
                Re: How to have an ASP page use a web service?

                > > All i need is to put the value 61 in a variable in the ASP page.[color=blue][color=green]
                > >[/color]
                >
                > Use an xml document.
                > After the Send statement:
                >
                > Set xmldoc = xmlhttp.respons eXML
                > thevalue = xmldoc.document Element.text
                > response.write thevalue[/color]

                Thank you Bob, that does what i wanted.

                Now only if i can find a simple ASP example that executes SOAP Action.



                Comment

                • Aaron Bertrand - MVP

                  #9
                  Re: How to have an ASP page use a web service?

                  > Now only if i can find a simple ASP example that executes SOAP Action.

                  Why? The result is still going to be an XML string you'll have to parse,
                  and Bob already gave you code that does that?


                  Comment

                  • serge

                    #10
                    Re: How to have an ASP page use a web service?

                    Yes, True Bob did give me the code i wanted.

                    But, i am somewhat confused about all this SOAP thing.

                    The web services i created in Visual .NET show me some code about SOAP
                    Action,
                    HTTP POST, GET etc...

                    So i am trying to try that SOAP ENVELOPE thing, see what is the difference.
                    Basically,
                    trying to learn, test and understand the differences.

                    If you happen to know a good book that explains SOAP and ASP or ASP.NET i
                    guess,
                    please let me know.

                    Thank you


                    "Aaron Bertrand - MVP" <aaron@TRASHasp faq.com> wrote in message
                    news:eVsDCYyQEH A.2876@TK2MSFTN GP09.phx.gbl...[color=blue][color=green]
                    > > Now only if i can find a simple ASP example that executes SOAP Action.[/color]
                    >
                    > Why? The result is still going to be an XML string you'll have to parse,
                    > and Bob already gave you code that does that?
                    >
                    >[/color]


                    Comment

                    Working...