Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-01
3
Medium Priority
?
340 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
[X]
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
3 Comments
 
LVL 26

Accepted Solution

by:
rdcpro earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

722 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