Click here to Skip to main content
13,633,768 members
Rate this:
 
Please Sign up or sign in to vote.
Dear all i have problem with WCF Service.

Administration WPF project (exe) is trying to read config file one of WCF service (Read AppSettings).
Application works properly, successfully read and write App.config file while in debug mode (as VS host Services automatically (Service host environment)), but when i deploy services on IIS, I face bellow exception.

Here is detail description of Exception


exePath must be specified when not running inside a stand alone exe.
Type: System.ArgumentException:
Source:
System.Configuration
Data:
Stack Trace: at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad)
at Business.XXXService.AdminService.ReadEmailConfiguration(GenericRequest`1 request) in E:\Source\MB Services\Source Code\Source Code\Business\NFS.Business.COSService\ServicesImpl\AdminService.cs:line 388


As I understand, In development mode, there is aap.config file for services (WCF Service library project), but when going to deploy on IIS, configuration read from Web.config
So I implemented both cases.
Here is implementation of reading config file, But still face issue on deployed Service.

Configuration configuration = null;

               if (HttpContext.Current != null)
                   configuration = WebConfigurationManager.OpenWebConfiguration("~");
               else
                   configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

               if (configuration == null)
               {
                   response.Status.Code = ReturnCode.DataNotFound.GetStringValue();
                   response.Status.Message = "Unable to read configuration";
                   return response;

               }


I think there is no need to investigate in app/web.config therefore I am not attaching config File



Thanks in Advance
Kamran
Posted 4-Jun-13 18:49pm
Updated 23-May-18 22:46pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Comments
M.Kamran Asim 5-Jun-13 5:33am
   
Thanks dude!
If you see question, I already implement this approach, but still issue, as HttpContext.Current is always null, if you have not enabled AspnetCompatibality.
So thats the point where Service was trying to read second option, and failed.
I have posted solution, please go through,

Thanks for your support.
   
I saw that solution also while searching, but thought this might help you better.

Anyway, good work, well done.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

If you don't can or want to enable asp compability just check WebOperationContext.Current != null instead of HttpContext.Current.

It's located in System.ServiceModel.Web.

Regards,
Patrik
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Dear All,

Issue Solved.

You need to enable asp compatibility bellow steps can solve such issue.

set AspnetCompatibilityEnabled true in web.config ServiceModel Node (If you are using WCF service library then add AspnetCompatibilityEnabled in ServiceModel Node in aap.config)

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
.
.
.
</system.serviceModel


Second you need to Add AspNetCompatibilityRequirements Attribute to compatible service with asp.net

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AdminService : IAdminService
    {
.
.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180712.1 | Last Updated 24 May 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100