Dll Created For Access App cannot locate web services configuration info in App.config file

I've been asked to push some data to an external web service using Access 2010. After researching this all day, it looks like many suggestions point to using Visual Studio to create a dll that utilizes VS's ability to auto generate the web services protocol code, reference then dll in Access and then call it from my Access 2010 VBA code. The web service code works great when bundled as a standalone exe. However, when I compile it into a dll, reference it within Access and then call it from by Access VBA code, I get the following error:

"Could not find the default endpoint element that references contract 'ServiceReference1.NameOfMyDllClass' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

After a little more digging, it appears that creating a dll does not include the app.config file that contains this configuration information so I'm guessing my DLL can't find the configuration information it needs to initiate the web service transfer. Most recommendations seem to suggest adding the info in the app.config file to the host's app.config but off course Access does not have anything like that.

With so many recommendations to use dlls that wrap the web services when using Access, it sounds like a great way to go but I must be doing something wrong. Any help to get me pointed in the right direction would be appreciated.
lacole8Asked:
Who is Participating?
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
you may need to write some codes then

something like this

Dim binding = New BasicHttpBinding()
    binding.Name = "MyServicesSoap"
    binding.AllowCookies = False
    binding.BypassProxyOnLocal = False
    binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
    binding.MaxBufferSize = 65536
    binding.MaxBufferPoolSize = 524288
    binding.MessageEncoding = WSMessageEncoding.Text
    binding.TextEncoding = System.Text.Encoding.UTF8
    binding.TransferMode = TransferMode.Buffered
    binding.UseDefaultWebProxy = True

    binding.ReaderQuotas.MaxDepth = 32
    binding.ReaderQuotas.MaxStringContentLength = 8192
    binding.ReaderQuotas.MaxArrayLength = 16384
    binding.ReaderQuotas.MaxBytesPerRead = 4096
    binding.ReaderQuotas.MaxNameTableCharCount = 16384

    binding.Security.Mode = BasicHttpSecurityMode.None
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
    binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None
    binding.Security.Transport.Realm = ""
    binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName
    binding.Security.Message.AlgorithmSuite = Security.SecurityAlgorithmSuite.Default

    'Define the endpoint address'
    Dim endpointStr = "http://services.mycompany.com/WebServices/MyServices.asmx"
    Dim endpoint = New EndpointAddress(endpointStr)
    'Instantiate the SOAP client using the binding and endpoint'
    'that were defined above'
    Dim client = New MyServicesSoapClient(binding, endpoint)

Open in new window

0
 
lacole8Author Commented:
I remember seeing this suggestion earlier today on another forum and attempted to locate where in my VS project that binding would take place.  I could not locate anywhere that looked like hard wiring the values would be appropriate.  Where in the project would you place this?

Or.... are you saying this is code I would place in my Access app and execute prior to calling the dll?
0
 
HainKurtSr. System AnalystCommented:
this code should be in your access

what is your current code in access?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
lacole8Author Commented:
I'm using a web service located at www.webservicex.net/New/Home/ServiceDetail/6 to test against and just prove if this will work...
My access code is pretty basic as follows:
Sub TestWebService()
  Dim clsWebServiceTest As New WebServiceTest.TestWebService
  Debug.Print clsWebServiceTest.TestGetBibleTitle()
End Sub

Open in new window

After using the Add Service Reference in VS, that code is pretty simple too
Imports WebServiceTest
Public Class TestWebService
    Public Function TestGetBibleTitle() As String
        Dim objWebServiceTest As New ServiceReference1.BibleWebserviceSoapClient
        Dim strResponse As String
        strResponse = objWebServiceTest.GetBookTitles()
        TestGetBibleTitle = strResponse
    End Function
End Class

Open in new window

0
 
HainKurtSr. System AnalystCommented:
the firs part is from access and you get error

2nd code is from VS and works

is that right?
0
 
lacole8Author Commented:
If I compile the VS code into a standalone exe, it works perfectly.  If I compile it into a class module and call it from my access app, I get the "ould not find the default endpoint element..." error.

the endpoint is defined in the app.config file and looks like the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BibleWebserviceSoap" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.webservicex.net/BibleWebservice.asmx"
          binding="basicHttpBinding" bindingConfiguration="BibleWebserviceSoap"
          contract="ServiceReference1.BibleWebserviceSoap" name="BibleWebserviceSoap" />
    </client>
  </system.serviceModel>   
</configuration>

Open in new window

One test I tried was to attempt to access the above info from my code and I received nothing back.  That was what led me down the path that the app.config file is not included in the .dll that is created and gave my current theory that the missing info is causing my problem.

Back to your suggested code, is that to support my VS code so that it can locate binding information or does it replace that code and make it so that it is not required?
0
 
lacole8Author Commented:
I added your suggested code to my access app and the BasicHttpBinding, EndpointAddress and MyServicesSoapClient are causing compile errors (user defined type not defined).  Is there a reference that needs to be added?
0
 
HainKurtSr. System AnalystCommented:
not sureö but maybe somethıng lıke thıs

Dim binding = New BasicHttpBinding()
binding.Name = "BibleWebserviceSoap"

'Define the endpoint address'
Dim endpointStr = "http://www.webservicex.net/BibleWebservice.asmx"
Dim endpoint = New EndpointAddress(endpointStr)

'Instantiate the SOAP client using the binding and endpoint'
'that were defined above'
Dim clsWebServiceTest As New WebServiceTest(binding, endpoint)

Dim strResponse As String
strResponse = clsWebServiceTest.GetBookTitles()

Open in new window

0
 
HainKurtSr. System AnalystCommented:
what is your access version

did you check this?
0
 
lacole8Author Commented:
2010.  

I'm getting a compile error on BasicHttpBinding as being a "user defined type not defined".  

Plus I'm struggling with how to covert the following statements to access vba...
Dim endpoint = New EndpointAddress(endpointStr)
Dim clsWebServiceTest As New WebServiceTest(binding, endpoint)

Open in new window

Plus, I don't understand what exactly the WebServiceTest(binding, endpoint) line is doing.
I really appreciate your help but I'm very confused at this point!
0
 
HainKurtSr. System AnalystCommented:
I don't have Access 2010 / VB6 with me...
I have Access 2016 and VS 2013
so I cannot test anything, sorry...
0
 
lacole8Author Commented:
Does the code you provided work in those versions?  I've got no problem upgrading if that is what is required.
0
 
HainKurtSr. System AnalystCommented:
I am checking access 2016 to find out how to access to that web service
once I find it out, I will post here...
0
 
lacole8Author Commented:
Thank you very much.

I was successful in getting this to work by moving the code you suggested into the VS dll as shown below:
  Public Function TestGetBibleTitle2() As String
    Dim binding = New BasicHttpBinding()
    binding.Name = "BibleWebserviceSoap"

    'Define the endpoint address'
    Dim endpointStr = "http://www.webservicex.net/BibleWebservice.asmx"
    Dim endpoint = New EndpointAddress(endpointStr)

    'Instantiate the SOAP client using the binding and endpoint'
    'that were defined above'
    Dim clsWebServiceTest As New BibleWebserviceSoapClient(binding, endpoint)

    TestGetBibleTitle2 = clsWebServiceTest.GetBookTitles()
  End Function

Open in new window

Calling the class function within access using the following then worked like a charm
  Dim clsWebServiceTest As New WebServiceTest.TestWebService
  Debug.Print clsWebServiceTest.TestGetBibleTitle2()

Open in new window

thank you very much for your patience and help.
0
 
lacole8Author Commented:
Thank you for your help.  While the comment marked best solution was not exactly what I needed it definitely started me down the right trail and ultimately the right solution.  Your help was invaluable.
0
 
HainKurtSr. System AnalystCommented:
did you install this?

Microsoft Office 2003 Web Services Toolkit 2.01

The Microsoft® Office 2003 Web Services Toolkit allows you to quickly access and use Web services with Visual Basic for Applications (VBA) from Microsoft Office 2003 applications.

https://www.microsoft.com/en-us/download/details.aspx?id=2224
0
 
HainKurtSr. System AnalystCommented:
I guess with this tool, you can connect to web service and get the data in tabular and use it in access as a table/view!
0
 
HainKurtSr. System AnalystCommented:
looks like that one is too old and you cannot use it with Access 2010

please check this

https://codingislove.com/http-requests-excel-vba/

I will test it
0
 
HainKurtSr. System AnalystCommented:
ok, this worked for me
I added "Microsoft XML v6.0" reference

Sub TestWebService()
    Dim xmlhttp As New MSXML2.XMLHTTP60
    Dim myurl As String
    myurl = "http://www.webservicex.net/BibleWebservice.asmx/GetBookTitles"
    xmlhttp.Open "GET", myurl, False
    xmlhttp.Send
    MsgBox (xmlhttp.responseText)
End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.