Solved

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

Posted on 2017-04-20
19
19 Views
Last Modified: 2017-04-20
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.
0
Comment
Question by:lacole8
  • 11
  • 8
19 Comments
 
LVL 51

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
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
 

Author Comment

by:lacole8
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
this code should be in your access

what is your current code in access?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:lacole8
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
the firs part is from access and you get error

2nd code is from VS and works

is that right?
0
 

Author Comment

by:lacole8
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
 

Author Comment

by:lacole8
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
what is your access version

did you check this?
0
 

Author Comment

by:lacole8
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
I don't have Access 2010 / VB6 with me...
I have Access 2016 and VS 2013
so I cannot test anything, sorry...
0
 

Author Comment

by:lacole8
Does the code you provided work in those versions?  I've got no problem upgrading if that is what is required.
0
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
 

Author Comment

by:lacole8
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
 

Author Closing Comment

by:lacole8
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Join & Write a Comment

Suggested Solutions

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

685 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