How do I pull back data from a C# web service to my vbscript page?

HELP!
I have to submit information to an API that is a c# web service and pull back the response.  I am experienced with ASP and VBScript but new to C#/Web Service/XML. Here is a tester that I have built that isn't working, I may have errors in several places.   Thanks.

**********************************THIS IS THE WEB SERVICE
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace sumThis
{
      /// <summary>
      /// Summary description for Service1.
      /// </summary>
      public class sumThis:WebService
      {
            public sumThis()
            {
                  //CODEGEN: This call is required by the ASP.NET Web

Services Designer
                  InitializeComponent();
            }

            #region Component Designer generated code
            
            //Required by the Web Services Designer
            private IContainer components = null;
                        
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if(disposing && components != null)
                  {
                        components.Dispose();
                  }
                  base.Dispose(disposing);            
            }
            
            #endregion

                  [WebMethod]
                  public int Add(int a,int b)
                  {
                        int sum;
                        sum=a+b;
                        return sum;
                  }            
      }
}
**********************************THIS IS THE TEST ASP

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
      <title>Untitled</title>      
      <!-- #include file="cdtest.vbs" -->
</head>
<% addAandB() %>
<body>
<form action="abtest.asp" method="post">

<table>
<tr>
      <td>a</td>      
      <td><input type="Text" name="ab" value=""></td>
</tr>
<tr>
      <td>&nbsp;</td>
</tr>
<tr>
      <td>b</td>      
      <td><input type="Text" name="bc" value=""></td>
</tr>
<tr><input type="Submit"></tr>
</table>
<%=tempLoc%>
</form>
</body>
</html>
**********************************THIS IS THE VBScript PAGE

<script language="vbscript" runat="server">

function addAandB()
dim vofa
dim vofb
dim tempLoc
vofa = request("ab")
vofb = request("bc")

Const URL = "http://localhost/sumThis/sumThis.asmx/Add"

Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST", URL, false

xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

xmlhttp.send "a=" & vofa & "b=" & vofb
'tempLoc = xmlhttp.responseBody
'response.write tempLoc

xmlhttp.loadXML
xmlhttp.responseText

end function


oshe127Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rdcproCommented:
There are several things wrong here, let me point those out first:

1.    Don't use this progID at all (it's MSXML 2):

Set xmlhttp = CreateObject("Microsoft.XMLHTTP")

and make sure you use the server-safe version:

Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP")


2.    Also, this isn't used here:

xmlhttp.loadXML

This will throw an exception as the loadXML isn't a method of this object.  The XMLHTTPRequest object is a messaging services, basically.  You call the send method, then look at the response.  If you're talking to a web service, you should get an XML response.  To see what the response is, you can use the responseXML property, which returns a parsed DOM Document object.  Or you can use the responseText to see what the actual text is (sometimes if there's an error, you'll get an HTML response.  Other times the response might not parse...).

If you want to see the results in the browser, you can simply do it like:

response.contenttype = "text/xml"
response.write xmlhttp.responseXML

But in your case, I think I would use the Soapclient to contact the web service.  It's much easier that way.  Download the Soap Toolkit, if you don't already have it.  Here's the syntax for the SoapToolkit 2.0:

set soapclient = CreateObject("MSSOAP.SoapClient")
soapclient.mssoapinit("Const URL = "http://localhost/sumThis/sumThis.asmx?wsdl", "", "", "")
Dim iReturn
iReturn =  soapclient.Add(vofa, vofb)


The mssoapinit() method takes four parameters:

bstrWSDLFile -- The URL of the WSDL file that describes the services offered by the server.  In your service, it should be (I think!!):
http://localhost/sumThis/sumThis.asmx?wsdl
Try variations on that in your browser until you find the wsdl.

bstrServiceName  -- (optional) The service in the WSDL file that contains the operation specified in the Simple Object Access Protocol (SOAP) request. If this parameter is missing, is null, or is an empty string, the mssoapinit method uses the first service in the specified WSDL file when initializing the SoapClient object.

bstrPort -- (optional) The name of the port in the WSDL file that contains the operation specified in the SOAP request. If this parameter is missing, is null, or is an empty string, the mssoapinit method uses the first port in the specified service when initializing the SoapClient object.

bstrWSMLFile --(optional) The URL of the Web Services Meta Language (WSML) file. This is a required parameter only when using custom type mappers, as described in Handling Complex Types.


Regards,
Mike Sharp
 

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oshe127Author Commented:
Thanks Mike,

I downloaded the soap kit and it doesn't work either.  This is how I revised my logic page:

<script language="vbscript" runat="server">

function addAandB()
dim vofa
dim vofb
dim tempLoc
dim iReturn

vofa = request("ab")
vofb = request("bc")

Const URL = "http://localhost/sumThis/sumThis.asmx/Add"

set soapclient = CreateObject("MSSOAP.SoapClient")

soapclient.mssoapinit URL,"","",""

iReturn = soapclient.Add(vofa, vofb)

end function
</script>
rdcproCommented:
If you type this:

http://localhost/sumThis/sumThis.asmx?wsdl

in your browser, do you see the wsdl?  Try various URLs, such as:

http://localhost/sumThis?wsdl

until you can see the wsdl.  That's the value you use in URL.

Once that's working, the .NET web services create a "sample" UI for interfacing with the service.  Can you see it?  

Regards,
Mike Sharp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.