I am attempting to call and consume an ASP.NET webservice with an MS Access database application using VBA. The webservice itself appears to be operable because I am able to consume it successfully using a separate ASP.NET web application. However, I am having a difficult time trying to get the VBA code within the Access database to return the correct data string from the webservice.
I’ve searched a number of different forums on this topic, but I cannot seem to locate the information that I need in order to get this to work the way that I need it to. That said, I am new to working with webservices in general.
Here is the code that I am using within my MS Access database:
Private Sub Command0_Click()
InvokeWebService ("http://localhost:51075/WebService1.asmx?HelloWorld")
End Sub
Public Function InvokeWebService(ByVal strUrlCommand As String) As String
Dim HttpReq As Object
Dim strWebCode As String
Dim fOk As Boolean
' Routine that calls the web site
Set HttpReq = CreateObject("MSXML2.XMLHTTP")
HttpReq.Open "GET", strUrlCommand, False
On Error Resume Next
HttpReq.send
fOk = (Err.Number = 0)
If fOk Then
strWebCode = HttpReq.responseText
Else
strWebCode = "Err"
End If
Set HttpReq = Nothing
InvokeWebService = strWebCode
End Function
Here is the code that I am using for the webservice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Webservice
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello to the World";
}
}
}
When I execute the code in my Access database, I’m looking to get the string “Hello to the world” returned to me. However, here is what is actually returned (to the VBA variable “InvokeWebService “) when I run the VBA code. I appreciate any advice on what I am doing incorrectly.
<html>
<head><link rel="alternate" type="text/xml" href="/WebService1.asmx?disco" />
<style type="text/css">
BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; }
#content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; }
A:link { color: #336699; font-weight: bold; text-decoration: underline; }
A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; }
A:active { color: #336699; font-weight: bold; text-decoration: underline; }
A:hover { color: cc3300; font-weight: bold; text-decoration: underline; }
P { color: #000000; margin-top: 0px; margin-bottom: 12px; font-family: Verdana; }
pre { background-color: #e5e5cc; padding: 5px; font-family: Courier New; font-size: x-small; margin-top: -5px; border: 1px #f0f0e0 solid; }
td { color: #000000; font-family: Verdana; font-size: .7em; }
h2 { font-size: 1.5em; font-weight: bold; margin-top: 25px; margin-bottom: 10px; border-top: 1px solid #003366; margin-left: -15px; color: #003366; }
h3 { font-size: 1.1em; color: #000000; margin-left: -15px; margin-top: 10px; margin-bottom: 10px; }
ul { margin-top: 10px; margin-left: 20px; }
ol { margin-top: 10px; margin-left: 20px; }
li { margin-top: 10px; color: #000000; }
font.value { color: darkblue; font: bold; }
font.key { color: darkgreen; font: bold; }
font.error { color: darkred; font: bold; }
.heading1 { color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal; background-color: #003366; margin-top: 0px; margin-bottom: 0px; margin-left: -30px; padding-top: 10px; padding-bottom: 3px; padding-left: 15px; width: 105%; }
.button { background-color: #dcdcdc; font-family: Verdana; font-size: 1em; border-top: #cccccc 1px solid; border-bottom: #666666 1px solid; border-left: #cccccc 1px solid; border-right: #666666 1px solid; }
.frmheader { color: #000000; background: #dcdcdc; font-family: Verdana; font-size: .7em; font-weight: normal; border-bottom: 1px solid #dcdcdc; padding-top: 2px; padding-bottom: 2px; }
.frmtext { font-family: Verdana; font-size: .7em; margin-top: 8px; margin-bottom: 0px; margin-left: 32px; }
.frmInput { font-family: Verdana; font-size: 1em; }
.intro { margin-left: -15px; }
</style>
<title>
WebService1 Web Service
</title></head>
<body>
<div id="content">
<p class="heading1">WebService1</p><br>
<span>
<p class="intro">The following operations are supported. For a formal definition, please review the <a href="WebService1.asmx?WSDL">Service Description</a>. </p>
<ul>
<li>
<a href="WebService1.asmx?op=HelloWorld">HelloWorld</a>
</li>
<p>
</ul>
</span>
<span>
</span>
</body>
</html>
Yes, I realize that I could create and reference a .NET DLL in my Access database to get this to work. However, I need to avoid the .NET dependency and would prefer to be free of the issue of having to maintain and distribute the extra DLL file; assuming that I can accomplish this task without that.