Solved

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

Posted on 2003-11-01
3
331 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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. 
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now