Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 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.

C#
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
Updated 23-May-18 22:46pm

 
Share this answer
 
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.
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
 
Share this answer
 
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)

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


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

C#
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AdminService : IAdminService
    {
.
.
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900