Link to home
Start Free TrialLog in
Avatar of oshe127
oshe127

asked on

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


ASKER CERTIFIED SOLUTION
Avatar of rdcpro
rdcpro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oshe127
oshe127

ASKER

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