Solved

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

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


0
Comment
Question by:oshe127
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
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:

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
 
0
 

Author Comment

by:oshe127
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
</script>
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 9672473
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
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET and XML parsing 6 78
Trouble parsing soap xml result 3 51
XSLT list item selection criteria not working 12 30
C# SQL BULK INSERT CLASS 5 48
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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

832 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