Reputation: 598
I have a DLL in .NET which uses a WebService (to send emails).
When I use the DLL in a project, it gives me an error unless I reference the webservice again.
I would like to not be forced to reference this in parent projects which use the DLL
To call the DLL, I simply do something like this:
Try
Dim x As New clsMail
Dim y As New clsMail.objMail
x.SendEmail(y)
Catch ex As Exception
e = ex.ToString
End Try
Is this possible since it is already referenced in the DLL?
If I remove the reference in the main project, I get an error from the Common DLL. If I add the Service reference to main project, then the error goes away.
I would like to be able to use this DLL and service by Only Importing the DLL without having to do any extra work. The point is to be able to import this DLL into many projects, without any extra steps in those projects.
Thanks in advance
Final Update:
Adding MailServer = New Mailserver.Service1SoapClient(New BasicHttpBinding(), New EndpointAddress("http://webmail/SendEmail.asmx") in the DLL itself Fixes this issue. I can now use in any project without having to reference the Web Service outside of the DLL
C# version:
MailServer.Service1SoapClient MailServer = new MailServer.Service1SoapClient(new BasicHttpBinding(), new EndpointAddress("http://webmail/SendEmail.asmx"));
Thank you
Upvotes: 2
Views: 796
Reputation: 127563
You likely don't need the entire service refrence added. The only thing beneficial adding the reference did was add settings in your App.config for the program for you, you did not need any of the files or classes it generated. All you need to do is copy the configuration settings in the app.config
that where auto-generated in WizardCommunications and copy them in to the App.config
in screenshot. It will then read the settings from the exe's config file and should work.
You also could manually hard code the settings (like the URL it connects to) from the app.config in to your library (by using constructors that let you pass in a URL) so it does not rely on the configuration for its settings.
UPDATE:
To hardcode the settings instead of using Dim MailServer as New MailServerClient
and using the constructor Public Sub New()
in Partial Public Class Service1SoapClient
you need to use the Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
constructor instead.
To do that you need to re-create the settings defined in your app.config file in the dll and pass that in as the two parameters. Here is a basic example of what one would look like, you will need to adjust it to fit your needs
Dim MailServer As New MailServer.Service1Client(New BasicHttpBinding(), New EndpointAddress("http://webmail/SendEmail.asmx"))
Once you do that you can just reference the dll of your project and not need anything in the app.config of the running exe.
Upvotes: 4
Reputation: 61
I would suggest creating a layer with common code which is going to be shared through all the solution.
So for example, screenshot.common
, then reference the service in common, so you only need to reference the service in a single place. Then wherever you need the common code just reference screenshot.common
.
I hope it helps!
Upvotes: 0