Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2017-04-20
19
Medium Priority
?
145 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 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 42101885
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
ID: 42101899
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 61

Expert Comment

by:HainKurt
ID: 42101902
this code should be in your access

what is your current code in access?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:lacole8
ID: 42101909
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 61

Expert Comment

by:HainKurt
ID: 42101912
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
ID: 42101920
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
ID: 42101924
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 61

Expert Comment

by:HainKurt
ID: 42101931
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 61

Expert Comment

by:HainKurt
ID: 42101935
what is your access version

did you check this?
0
 

Author Comment

by:lacole8
ID: 42101940
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 61

Expert Comment

by:HainKurt
ID: 42101945
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
ID: 42101948
Does the code you provided work in those versions?  I've got no problem upgrading if that is what is required.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 42101954
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
ID: 42101955
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
ID: 42101957
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 61

Expert Comment

by:HainKurt
ID: 42101961
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 61

Expert Comment

by:HainKurt
ID: 42101963
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 61

Expert Comment

by:HainKurt
ID: 42101969
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 61

Expert Comment

by:HainKurt
ID: 42101971
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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

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…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

824 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