Basically my situation is this:
Windows Service --Calls--> MethodinDLL --Calls--> WCFService.
Service configuration is written on the DLL side manually, and on windows service side in config - I am insterested if WCF parameters on DLL side and on the Windows service side should match. More elaboration below.
I will tell you my setup. I call WCF Service from DLL. There is code inside DLL which calls WCF service such as this:
//Inside DLL
BasicHttpBinding binding = new BasicHttpBinding(SecurityMode.None);
EndpointAddress epa = new EndpointAddress("http://localhost:16593/FreeSpaceDatabase.svc");
YourServiceClient proxy = new YourServiceClient(binding, epa);
I manually provide parameters as you can see.
Now, I have a windows service which actually refers to this DLL, and using DLL (or via DLL), calls the WCF Service. (The call to WCF Service is located in DLL - windows service doesn't have method to call WCF Service).
But I was forced to still add this on the Windows service side:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFreeSpaceDatabase" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:16593/FreeSpaceDatabase.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFreeSpaceDatabase"
contract="ServiceReference1.IFreeSpaceDatabase" name="BasicHttpBinding_IFreeSpaceDatabase" />
</client>
</system.serviceModel>
</configuration>
My question is what if the EndpointAddress("http://localhost:16593/FreeSpaceDatabase.svc") which I specify in the code on the DLL side(like in the beginning of my question):
EndpointAddress epa = new EndpointAddress("http://localhost:16593/FreeSpaceDatabase.svc");
is different from the endpoint address specified in the AppConfig file as of the Windows service? Is it allowed? Or they should always be the same?
You can remove this address from your config and it should work. I have these settings (bindings and endpoints) in my code and only this in my config:
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
Related
I am currently implementing a plugin for a third party application in C#. The plugin is a library (DLL) and it calls some Web services. So, I created a Service Reference in Visual Studio, which is configured in the app.config file of the plugin as such:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticationEndpointImplServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/services/auth"
binding="basicHttpBinding" bindingConfiguration="AuthenticationEndpointImplServiceSoapBinding"
contract="AuthenticationWebService.AuthenticationEndpoint"
name="AuthenticationEndpointImplPort" />
</client>
</system.serviceModel>
</configuration>
I have another project, that I use for testing the plugin. When I call the service from that project, it works fine, provided I have copied the same configuration to this project's app.config file also. But when I build the plugin and run it from within the third party application, I get the following message:
Could not find default endpoint element that references contract
'AuthenticationWebService.AuthenticationEndpoint' 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.
I suspect the reason for the error is the fact that there is no configuration file for the third party application. Do you have any ideas how to work around this?
You could set up your parameters(binding, endpoint, etc.) explicitly in your plugin code after reading them from ordinary text file...
Here you will find some example:
https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx
I have a ASP .NET MVC app that I want to be able to connect to SOAP API.
I have created a wrapper project were I have my common methods that are working with the API. I have created this wrapper because the file generated by tool is so huge the project build would take ages.
From api doc site:
The tool then generates a single file named EconomicWebService.cs with the proxy code. This file can then be included directly in a project (this can slow down your Visual Studio as it is a rather big file) or built into a dll that can be referenced from your project)
I have referenced this wrapper as dll in my class library (middle layer) that is referenced into my MVC application.
Sadly it is not working, and I am getting this error:
Could not find default endpoint element that references contract 'S2s.Economic.WebService.EconomicWebServiceSoap' 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.
Webconfig
<system.web>
.....
</system.web>
<runtime>
...
</runtime>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EconomicWebServiceSoap">
<security mode="Transport" />
</binding>
<binding name="EconomicWebServiceSoap1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://api.e-conomic.com/secure/api1/economicwebservice.asmx"
binding="basicHttpBinding" bindingConfiguration="EconomicWebServiceSoap"
contract="PTS.S2s.Economic.WebService.EconomicWebServiceSoap"
name="EconomicWebServiceSoap" />
</client>
</system.serviceModel>
</configuration>
I have managed to find a workarround with manual endpoint setup in the code.
EndpointAddress endpoint = new EndpointAddress( "https://api.e-conomic.com/secure/api1/economicwebservice.asmx" );
I'm trying to access Sharepoint 2010's Lists.asmx web service. I've created new console project in C#, added reference to a web service (http://[SITE]/_Vti_Bin/Lists.asmx) and it found the Lists web service all right. However, when I try to do
ListsService.Lists objLists = new ...
It says that Lists does not exist! In object viewer, I see all sorts of things in the ListsService namespace:
AddAttachmentRequest
AddAttachmentRequestBody
....
but I don't see Lists. However, every example I found online says that after I add a reference, I should have Lists in the namespace...
What am I doing wrong?
EDIT: app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ListsSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://SITE/_Vti_Bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="ListsService.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
</configuration>
Make sure you are doing ListsService.Lists objLists = new ListsService.Lists() (not "new Lists()")
Make sure that the web service reference is setup correctly in the Settings.settings file and web.config/app.config file. Try removing the web service reference and re-adding it
The problem was that I have created "service" reference, not a "web service" reference. You have to click "Advanced" and then "Add Web Service reference" in order to add a web service refernce, otherwise it creates a WCF service reference that works differently.
I am currently working on a WPF Application, using a different project to call a WebService.
When I try to build i get this error:
Could not find default endpoint element that references contract
'VisitorRegistrationWebService.VisitorRegistrationWebServiceSoap' 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.
The app.config from my webservice project is just the same as the one from my WPF project.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="VisitorRegistrationWebServiceSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/webservices/VisitorRegistrationWebService.asmx"
binding="basicHttpBinding" bindingConfiguration="VisitorRegistrationWebServiceSoap"
contract="BasicVisitorRegistrationWebService.VisitorRegistrationWebServiceSoap"
name="VisitorRegistrationWebServiceSoap" />
</client>
</system.serviceModel>
</configuration>
The strange thing is that I can run the project and use the webservice to get data, but the error will not go away, no matter how many times I clean and rebuild my solution.
in error message, contract name is 'VisitorRegistrationWebService.VisitorRegistrationWebServiceSoap'
and in endPoint configuration, contract="BasicVisitorRegistrationWebService.VisitorRegistrationWebServiceSoap"
I am adding a WCF client via “Add Service Reference” to the Class project with Visual Studio 2012. However I am getting the well known error:
Could not find default endpoint element that references contract ‘Service1.IService1′ 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.
The steps I followed was : (1) Create the Service1.cs and output.config via svcutil.exe, (2) Add service reference I am giving reference namespace as “MyFirstWcfWebServiceReference”. (3) add your existing Service1.cs file to the project. (4) in app.config Removed “MyFirstWcfWebServiceReference” and keep only IService1 in contract, (6) Build Project.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WCFServiceBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/webiste/WebService.svc"
binding="basicHttpBinding" bindingConfiguration="WCFServiceBinding"
contract="IService1" name="WCFServiceBinding" />
</client>
</system.serviceModel>
</configuration>