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.
************************** ********TH IS 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;
}
}
}
************************** ********TH IS 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> </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>
************************** ********TH IS 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.XM LHTTP")
xmlhttp.open "POST", URL, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur lencoded"
xmlhttp.send "a=" & vofa & "b=" & vofb
'tempLoc = xmlhttp.responseBody
'response.write tempLoc
xmlhttp.loadXML
xmlhttp.responseText
end function
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.
**************************
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;
}
}
}
**************************
<!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> </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>
**************************
<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.XM
xmlhttp.open "POST", URL, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur
xmlhttp.send "a=" & vofa & "b=" & vofb
'tempLoc = xmlhttp.responseBody
'response.write tempLoc
xmlhttp.loadXML
xmlhttp.responseText
end function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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.SoapC
soapclient.mssoapinit URL,"","",""
iReturn = soapclient.Add(vofa, vofb)
end function
</script>