WCF: System.Configuration.ConfigurationErrorsException - c#

I created a simple WCF service In solution and added a console application project to the solution to call the WCF service. When i debug chat solution it give me the following error. The WCF service was working fine when i tested it.
ServiceHost host = new ServiceHost(typeof(EvalService));
Resulting error:
A child element named 'service' with same key already exists at the
same configuration scope. Collection elements must be unique within
the same configuration scope (e.g. the same application.config file).
Duplicate key value: 'EvalServiceLibrary.EvalService'.
(C:\Users\User_Name\Documents\Visual Studio
2010\Projects\ChatSolution\ConsoleHost\bin\Debug\ConsoleHost.vshost.exe.Config
line 14)

I got the same error, but in my case I was creating a service using a previously used name. Sometimes, even if you delete the service file/code from the solution, its corresponding definition in the App.Config file remains un-updated.
I did a Quick Find (Ctrl+F) over the whole solution and typed the name of the service I was using. It located the piece of code in the App.Config file where the service is defined.
I deleted it and created the service using the same name.

It's all written in the exception message. You have two services in your app.config defined with the same key. Just look through the app.config in your console app, it shouldn't be hard to find.

Related

No connection string named 'CREntities' could be found in the application config file

I have 2 web-services. The first has a wsHttpBinding binding, the second is the wsDualHttpBinding. Also there is a project that hosts these web services.
In both services I use EF 6.0. In the service with binding wsHttpBinding, everything works fine. In the service with binding wsDualHttpBinding when accessing the server, an error occurs - "No connection string named 'CREntities' could be found in the application config file."
What am I doing wrong?
EDIT
I read that the connection string should be added to the hosting project, but then why does everything work to bind wsHttpBinding? I've added a connection thread to the host project, but this did not help, there is an error in the lack of the EF library.
"No connection string named 'CREntities1' could be found in the application config file."
That is correct. You need to fix it.
You can either pass in a value different from your default to the context constructor, or you can rename your connection string from "CREntities" to "CREntities1" in your config file.
That said, in the future, please don't post pictures of code, post code.
I'm so dumb that I just do not have words. No project for hosting needs to be created, Visual Studio will customize everything if you created the WCF Aplication project. A good example of how this works is here: https://www.youtube.com/watch?v=VA4r-iYCPQY&t=819s
I'm sorry that I wasted your time, I hope someone will need it. (No)

Services of differnt name having 2 exe

i have 2 exe files named as ActiveGateway.exe and ActiveLBS.exe which is running on window service ACTIVEServer and i copied that service and change its name as ActiveServer1 and 2 exe as Gateway.exe and LBS.exe.and change the installation path .after this if we trying to insatl this service it shows an error.this version already exist.i changed the version number product name and all..but still issue is like this
All that needs to be done is to make sure that the name of each service installation instance is unique. Then you need to have copies of installation directories for each service instance you'd like to have. Finally, you need to be able to set the service name dynamically during installation and startup. This will be facilitated using the app.config file.
The cleanest and most readily available way of providing the service name is to use an app.config file for your service and create an appSettings key that can be read from to set the service name. An app.config file needs to be added to your solution if one doesn't already exist to store the unique service name in order to dynamically set the ServiceInstaller.ServiceName and the ServiceBase.ServiceName to the same service name value you added to your configuration.
Source: http://www.codeproject.com/Articles/21320/Multiple-Instance-NET-Windows-Service

how to host silverlight project local

i want to debug my program but i can't host my silverlight project in VS 2010
here is the message that the VS send to me:
"the Silverlight project you are about to debug uses web service. Call to the web service will fail unless the Silverlight is host and launched from the same web project contains the web service"
when I search about it in the web i saw that the problem is that I'm not doing it local
so when I tried to change this line
endpoint address="http://xxx.xx.x.x/WebService/Service1.svc"
to
endpoint address="http://localhost/WebService/Service1.svc"
on this file:
ServiceReferences.ClientConfig
update!!
i tried now to do it like this:
endpoint address="http://localhost:54502/Service1.svc"
and i got and error that says:
the remote server returned an error:NotFound
here:
public int EndAddParticipant(System.IAsyncResult result) {
object[] _args = new object[0];
int _result = ((int)(base.EndInvoke("AddParticipant", _args, result)));
return _result;
what should i do to change it?
i saw that i need to turn on the debug in web.config file but it was already on.
You didn't explain well so here are a bunch of answers:
When you created your solution, you should have told it to host in a web site.
You can do this after the fact but it is a lot of work (for a new guy), you're better off starting over and copying your code from your silverlight project.
If you did but you are trying to connect to another web site as your web service, you will have to implement a Cross Domain configuration file. This opens a big security hole though.
If you have the 2 projects, but your issue is just the "ServiceReferences.ClientConfig" file not pointing the the right server, you need to include the PORT when debugging locally. It should look something like this:
http://localhost:12345/Service1.svc
Where 12345 is the port of your local web service. You can find this out by looking at the "Web" tab of your project properties.
Hope one of these does it. If not, please provide a little more info, like all the important stuff behind the phrase, "it didn't work"!

How to Call a Web Service in C#

I searched many examples of how to consume webservices methods with C#,
but all of them say to right click and add a service reference and type the address.
However I dont know why, but the webserver wich I am trying to connect does not work with this...
Here the address
https://bauru.sigiss.com.br/bauru/ws/sigiss_ws.php?wsdl
Can someone help me how could I interact with this specific webservice?
Using the WcfTestClient1 shows an error (that is probably the one you're running in to on an import):
Error: Cannot import wsdl:portTypeDetail: The ' ' character, hexadecimal value 0x20, cannot be included in a name.Parameter name: nameXPath to Error Source: //wsdl:definitions[#targetNamespace='urn:sigiss_ws']/wsdl:portType[#name='WebService SigISSPortType']Error: Cannot import wsdl:bindingDetail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='urn:sigiss_ws']/wsdl:portType[#name='WebService SigISSPortType']XPath to Error Source: //wsdl:definitions[#targetNamespace='urn:sigiss_ws']/wsdl:binding[#name='WebService SigISSBinding']Error: Cannot import wsdl:portDetail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='urn:sigiss_ws']/wsdl:binding[#name='WebService SigISSBinding']XPath to Error Source: //wsdl:definitions[#targetNamespace='urn:sigiss_ws']/wsdl:service[#name='WebService SigISS']/wsdl:port[#name='WebService SigISSPort']Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
I don't know enough about the service, but you may take a look at Can I create an element with forward slash as part of the name and find it's probably an attribute being used to decorate a property (which has a space in it).
1 WcftestClient can usually be found in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\
If for whatever reason you can't get to it (e.g. a proxy server is used where you're working) then simply go to the WSDL in your browser, save the page as an XML file on disk, and when adding a service reference again don't put in the web URL, put the path to it on disk (e.g. C:\temp\wsdl.xml).
Finally I got someone who had the exaclty same problem as I did! He said to do the following:
For Windows Vista, Windows 7 e Server 2008:
Start>Run
Regedit
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/SecurityProviders/Schannel/Protocols
Right Click on Protocols -> New -> Key
Name: TLS 1.0
Right Click on the new key -> New -> Key
Name: Client
Select the created folder (Client), right click New -> Value DWORD
Name: Enabled
After that just add the reference to your project. To avoid happening the same in your app users, force the SSL use before instanciate the webservice:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;

Why does my Event Log source keep getting put under "Application" in the registry instead of <log>?

I'm trying to create a windows service and I need it to be able to write to the event logs. I've added an EventLog component to my Service project, and set the Log property to be ccs_wscln_log and the Source property to be ccs_wscln (same name as the service).
I have also created and installer for this project. My problem is that whenever I install the service, it creates the ccs_wscln registry key under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application
when it SHOULD be
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\ccs_wscln_log.
The problem with this is that when I try to launch the service, I get an error that says
"The source 'ccs_wscln' is not registered in log 'ccs_wscln_log'. (It is registered in log 'Application'). The source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the source property'.
I've found that if I delete the ccs_wscln registry key under the Application folder, when I start the service it will run and generate the ccs_wscln_log entry under EventLog. So my question is, when I install the application, why is it creating an entry for me automatically under Application, and how do I prevent it from doing this?
I found another post on SO that said I need to restart my computer if I had installed it before under Application, so I tried that but when I reloaded the solution, I couldn't even bring up the designer because it was complaining that the registry entry was missing and it would still install under Application anyways.
I created a tutorial for creating a Windows service from scratch using C#. I address the issue of writing to an application-specific log. See Step 9 here for details.
I think, you would need following in your ServiceInstaller class.
this.Installers.Clear();
Above code needs to be just before you are adding a range of installers.
That is because, EventLogInstaller is added by default. Calling clear will remove it.
Alternatively, you can loop through the installers collection, select the specific type (EventLogInstaller) and assign it required LogName and EventSource name.

Categories