C# WCF cant see app.config - c#

Ok so here is my scenario.
I have made a WCF Library project. Configured my app.config file. I then created a new console application. Added my WCF Library project to the console app. Then I copied the config file over to my server console app. However, when I run the console application it throws an exception and essentially states that it cant see the app.config file. However, the app.config is clearly inside of the server console application. I can add my endpoints programmatically and make the service work. However, that is not my intention. Is there some sort of trick in order to get the ServiceHost to use the app.config, or more importantly the project to see the app.config?
My app.config
<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="serviceBehavior" name="Services">
<endpoint address="CompanyService" binding="netTcpBinding" bindingConfiguration=""
name="NetTcpBinding" contract="Services.ICompany" />
<endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8732/Services/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
My Host Service code:
using (ServiceHost host = new ServiceHost(typeof(Company))) {
host.Open();
Console.WriteLine("Press <ENTER> to terminate the host service");
Console.ReadLine();
}
It then throws this exception:
Unhandled Exception: System.InvalidOperationException: Service 'Services.Company' has zero application (non-infrastructure) endpoints. This might
be because no configuration file was found for your application, or because no
service element matching the service name could be found in the configuration fi
le, or because no endpoints were defined in the service element.

What are you naming the app.config file when you copy it over to the console app? There are specific rules that will need to be followed.
If the console app has an executable name of, e.g. "consoleapp.exe", then the app.config will have to have the name "consoleapp.exe.config"

Is the problem that you have called the file app.config, and not yourprogramname.exe.config?

#Jaochim The error says it's looking for a service named Services.Company while your config seems to have it attributed with name="Services" Try changing that.

Related

Trouble with WCF and WAS with web site and web service in separate application pools

None of the members of my team has ever been able to get a particular WCF service in our solution to work on our local machines. We've inherited it in legacy code and are trying to replace it, but it's very difficult to tell what it's doing since we can't run the debugger on it and we can't even get a response from it while debugging the main site that uses it.
The main part of our application is a web site. This particular service is hosted in a separate application pool on IIS due to some problems with using Excel interops (which this service uses) in the same app pool as the main site.
The service appears to use net.tcp for the protocol, and I have enabled the Windows Communication Foundation Non-HTTP Activation feature on my machine. I have also enabled the protocol on the Default Website and the node underneath it which is the WCF service in question (is this redundant?).
I can attach the debugger to w3wp.exe processes for both the site and the service. When the site makes the call to the service, however, an error is immediately returned and no breakpoints in the service are hit. The error reads:
The service 'MySvc.svc' cannot be activated due to an exception during
compilation. The exception message is: The type 'MyNamespace.MySvc',
provided as the Service attribute value in the ServiceHost directive,
or provided in the configuration element
Note, I have obviously redacted the real service name, etc, from this post. After attempting to follow solutions proposed on numerous similar questions, I have gotten nowhere. I am wondering if the problem is exacerbated by the separate app pools.
Below is the Web.config from the service project. The SVC file is named UploadAndImport.svc.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<!-- REDACTED SECTIONS PERTAINING TO LOGGING AND ENTERPRISE LIBRARY -->
</configSections>
<!-- REDACTED SECTIONS PERTAINING TO LOGGING AND ENTERPRISE LIBRARY -->
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.6.1" />
<identity impersonate="true" />
<pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="ProjectName.UploadAndImport">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="" name="ExcelServiceEndPointHTTP" contract="ProjectName.IUploadAndImport" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint binding="netTcpBinding" bindingConfiguration="" name="ExcelServiceEndPointTCP" contract="ProjectName.IUploadAndImport" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!-- This line ignores the error that 'An ASP.NET setting has been detected that does not apply in Integratd managed pipeline mode (system.web/identity#impersonate is set to true)'-->
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>
The directive in the SVC file looks like this:
<%# ServiceHost Language="VB" Debug="true" Service="ProjectName.UploadAndImport" CodeBehind="UploadAndImport.svc.vb" %>

Hosting WCF service from separate dll in WCF service application

I have a WCF service in a service library and I'm trying to host it in a WCF service application. I modified the .svc file accordingly
<%# ServiceHost Language="C#" Debug="true" Service="Mandrake.Service.OTAwareService" Factory="Mandrake.Service.OTServiceHostFactory" %>
And I added the stuff that was originally in the service library's app config to the service application's web.config file. I thought it overrides the settings defined in the library's app.config, but it turned out if I remove the app.config file from the library and host the service application on IIS with the web.config containing the necessary endpoint setup (which worked previously) the service doesn't get started and says I have no endpoint defined.
My web.config's servicemodel section is as follows:
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Mandrake.Service.OTAwareService"
factory="Mandrake.Service.OTServiceHostFactory"
relativeAddress="OTService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="StandardBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Mandrake.Service.OTAwareService" behaviorConfiguration="StandardBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8062/OTService"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
<endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Is there a way I can host this service from the service library in my service application?
Most probably you may not have net.tcp binding enabled on website where you are hosting your service application. Check in iis if net.tcp is there in list of bindings.

Facing issue with WCF: Could not find default endpoint

I created a WCF service in separate project name is AaWs then added this project in a website project as a reference . website project name is AaNuWs
in website project web.config file is
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="AaWs.RxtraIntroService">
<endpoint address ="AaWs" binding="basicHttpBinding" contract="AaWs.IRxIntro">
</endpoint>
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8080" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
then uploaded this website project on my web server.
then give the service reference in my new project from my website with a name space
IntroService
http://mywebsite/IntroService.svc?wsdl
new system create a new app.config file for me
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IRxIntro" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mywebsite/IntroService.svc/RecoverInfoTechAaWs"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRxIntro"
contract="IntroService.IRxIntro" name="BasicHttpBinding_IRxIntro" />
</client>
</system.serviceModel>
</configuration>
but now when i trying to access this service i am getting a error.
System.InvalidOperationException: Could not find default endpoint
element that references contract 'IntroService.IRxIntro' 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.
please help me on this
You need to confirm that the app.config is in the root folder with your executable. Then confirm that the app.config has the proper value for:
<client>
<endpoint ... contract=""
From the information you provided, the address information does not look correct. Your service has an overall address of "http://localhost:8080/AaWs" but your service reference (wsdl url) shows "http://mywebsite/IntroService.svc?wsdl". You surely want to make sure that you are pointing to the correct service when generating the reference.
Remove name="BasicHttpBinding_IRxIntro" attribute from endpoint configuration of app.config.

Localhost WCF service unavailable after stopping debug

I have problem reaching my WCF service on localhost. When I start it from Visual Studio, everything is fine. However, as soon as I stop debugging it, the service is no longer available. This is odd, because it happens only with projects created by myself. When I download a solution (e.g. this one), everything is just fine and the service is available also after I stop debugging it.
Thus, I suppose, it is a configuration problem. However, I am not able to find it. Here is my Web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name ="svcbh">
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name ="DuplexServer.CalculatorService" behaviorConfiguration ="svcbh" >
<host>
<baseAddresses>
<add baseAddress = "http//localhost:3435/CalculatorService/" />
</baseAddresses>
</host>
<endpoint name ="duplexendpoint"
address =""
binding ="wsDualHttpBinding"
contract ="DuplexServer.ICalculatorDuplex"/>
<endpoint name ="MetaDataTcpEndpoint"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
It sounds like the settings for your solution/project is not what you desire. Go the properties of your WCF project and look at "Web" settings(plenty of information on the net about this)
You will probably need to change from "Use Visual Studio Development Server" to "Use local IIS Web Server"
Assuming you are using IIS Express, it's usually caused by Edit and Continue (Right click the project, select properties. It's a checkbox in the Web tab).
Disable this, and the service should keep running when you stop debugging.
On a related note, if you wish to simply start the service to have available (i.e. you don't want to debug, you just want it running), you can use "Start without Debugging" in the Debug menu (CTRL + F5 by default)

WCF Service fails to load in Cassini with a metadata error

This is my first WCF service and I am having what seems to be a common problem for newbies i.e. the configuration file.
The service project was created with examples from here and here and after receiving the error [Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.], I went through the MSDN way of Web.config here and here.
Here is my Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Parkalot.WcfClient.Services.UserService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:7349/ServiceMetadata" />
</baseAddresses>
</host>
<endpoint address="/UserService" binding="wsHttpBinding" contract="Parkalot.WcfClient.Services.IUserServiceContract" />
<!-- Adds a WS-MetadataExchange endpoint at "http://localhost:7349/ServiceMetadata/mex" -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<!-- Enables the IMetadataExchange endpoint in services that -->
<!-- use "metadataSupport" in their behaviorConfiguration attribute. -->
<!-- In addition, the httpGetEnabled and httpGetUrl attributes publish -->
<!-- Service metadata for retrieval by HTTP/GET at the address -->
<!-- "http://localhost:8080/ServiceMetadata?wsdl" -->
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:7349/ServiceMetadata?wsdl" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
The error details are:
Error: Cannot obtain Metadata from http://localhost:7349/Services/UserService.svc
If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.
For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error URI: http://localhost:7349/Services/UserService.svc
Metadata contains a reference that cannot be resolved:
'http://localhost:7349/Services/UserService.svc'.
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
HTTP GET Error URI: http://localhost:7349/Services/UserService.svc
There was an error downloading 'http://localhost:7349/Services/UserService.svc'.
I have stripped a ton of lines from the error which is probably meant to render in a browser. Since I am running from within Visual Studio, I do not have a browser context.

Categories

Resources