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

Posted on 2003-11-01
Last Modified: 2012-05-04
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

            #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)

                  public int Add(int a,int b)
                        int sum;
                        return sum;
**********************************THIS IS THE TEST ASP

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

      <!-- #include file="cdtest.vbs" -->
<% addAandB() %>
<form action="abtest.asp" method="post">

      <td><input type="Text" name="ab" value=""></td>
      <td><input type="Text" name="bc" value=""></td>
<tr><input type="Submit"></tr>
**********************************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") "POST", URL, false

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

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


end function

Question by:oshe127
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 26

Accepted Solution

rdcpro earned 250 total points
ID: 9667527
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:


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!!):
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.

Mike Sharp

Author Comment

ID: 9671387
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
LVL 26

Expert Comment

ID: 9672473
If you type this:


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


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?  

Mike Sharp

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trouble parsing soap xml result 3 74
Shredding xml into an oracle 11g Database 2 92
export vdswitch fails in web client and in powercli 6 97
Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question