I been following/studying nopCommerce for a while now. Looking at this project am picking up few of its implementation techniques in my sample project utilizing Adventureworks DB. excluding plugin architecture from this project How can i implement WCF services on top of Nop.Services projects utilizing dependency injection and IOC containers.
Can anyone help me driving in right path?
Here is my solution:
I created WCF service under a new folder in nop structure.
then in wcf web.config I have added this config below
<configSections>
<section name="NopConfig" type="Nop.Core.Configuration.NopConfig, Nop.Core, Version=3.7.0.0, Culture=neutral" requirePermission="false" />
</configSections>
<NopConfig>
<DynamicDiscovery Enabled="true" />
<Engine Type="" />
<Themes basePath="~/Themes/" />
</NopConfig>
(but make sure you have added config section node on the top of the other configuration nodes)
Copy Settings.txt and InstalledPlugins.txt files into WCF/AppData folder
then in svc file I have added a private IProductService variable and constructor that calls using EngineContext and assign the variable which is like below. this will register the services
private readonly IProductService _productService;
public ProductWS() //servie constructorı
{
this._productService = EngineContext.Current.Resolve<IProductService>();
}
create your domains in wcf and assign them with [DataContract] and [DataMember]
Hope it helps
Related
The settings of referenced here was introduced as
Here are instructions for enabling the agent for .NET Framework and.NET Core.
https://docs.newrelic.com/docs/apm/agents/net-agent/installation/install-net-agent-windows/#app-config
It shows the following configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="NewRelic.AgentEnabled" value="true" />
<add key="NewRelic.AppName" value="DataServices" />
</appSettings>
But for ASP.NET Core, you don't use XML configuration, you use appsettings.json:
What are the configuration for ASP.NET Core?
Can the configuration be added to the Configuration of Azure Web App Service rather than in the local appsettings.json ? And if so, what are the keys?
In the doc page you provide, it is explained how to set it up in dotnet core.
You don't need to add anything to the appsettings file; just set an environment variable. Beware that it must be set only in the project's scope or all dotnet core applications running on the host will be monitored.
CORECLR_ENABLE_PROFILING=1
They provide a helpful link to a page with even more details: https://discuss.newrelic.com/t/setting-net-core-agent-environment-variables-per-process/157750
In addition to the methods they mention, you could also put the variable in a .env file and load it, for example as explained here https://dusted.codes/dotenv-in-dotnet
It is my understanding that when you deploy a service library the app.config not required as the host does not acquire nor use this file and instead uses its own app.config file! Hence why you have to put the database connection string in the hosts config file.
However, what I don't understand is how do you provide configurations within service library?! I realise that question may not be clear so let me provide an example...
In my service library I make use of the entity framework - upon adding the ado.net (via the wizard) the following was added to the app.config file:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
So, I am not going to claim to know exactly how purposeful these tags/settings are, but as a quick test I removed them and ran the host and the service worked the same as ever... so this got me thinking! Firstly, I imagine removing these tags didn't affect the service as there are default settings in place which will have been implemented by the entity framework?! and secondly what IF I am required to add specific entity framework configurations at a later date? How would I do that when the config file within the service library is redundant?
Of course this may not be deemed the best example of the "problem" I am trying to portray, but I hope you can understand my confusion and I would greatly appreciate an explanation regarding this scenario!
I've installed VS 2012 and am successfully using it on some web projects, but something with it has caused my web service project to break. I'm still using VS 2010 on the web service project and have not opened it in 2012.
Everything compiles and works correctly except when it tries to create an instance of a class in my referenced weblog project, then it throws this error:
This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked.
I can not find anywhere in the project where GetBufferlessInputStream is used explicitly.
If I jump over the weblog code, everything executes correctly.
I can't find anyone else who has received this error to try and narrow it down, any ideas where to start?
Stack
at System.Web.HttpRequest.get_InputStream()
at OAS.Web.Log.WebEvent..ctor(EventType type, HttpContext context, String applicationName)
at OAS.Web.Log.WebTrace..ctor(HttpContext context, String applicationName)
at OAS.Web.AdvisorServices.Extensions.OperationLoggerParameterInspector.BeforeCall(String operationName, Object[] inputs) in C:\SourceControl\OAS\IM.NET3.0\Web\AdvisorServices\OAS.Web.AdvisorServices.Extensions\OperationLogger\OperationLoggerParameterInspector.cs:line 54
**EDIT - Bonus Question
Why are these Framework 4.5 properties affecting my 4.0 solution?
Note : This issue has been fixed in .net 4.5.1. You can see the fix with 4.5.1. Once you have .net 4.5.1 add the following appSetting to switch back to the old behavior.
<configuration>
<appSettings>
<add key="wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode" value="true" />
</appSettings>
</configuration>
Here is how you can create a HttpModule to force ReadEntityBodyMode to be "classic" : http://blogs.msdn.com/b/praburaj/archive/2012/09/13/accessing-httpcontext-current-request-inputstream-property-in-aspnetcompatibility-mode-throws-exception-this-method-or-property-is-not-supported-after-httprequest-getbufferlessinputstream-has-been-invoked.aspx
To answer your other question (Why are these Framework 4.5 properties are effecting my 4.0 solution?):
.net 4.5 is an in-place upgrade of .net 4.0. So even if your project is targeting 4.0, since VS 2012 installs 4.5 runtime, some of the 4.5 behaviors take effect.
EDIT
Blog Entry:
In .net 4.5 WCF leveraged the buffer less input stream for scalability benefits. As a result when you try to access the HttpContext.Current.Request.InputStream property you may end up with the below exception, as the InputStream property tries to get you handle to the Classic stream as they both are incompatible.
“This method or property is not supported after
HttpRequest.GetBufferlessInputStream has been invoked.”
If you had a WCF 4.0 app which worked perfectly but on upgrading your .net framework to 4.5 you notice the service failing on accessing this property, here is the way to work-around the issue:
Add a simple HttpModule in the same WCF project which will access the InputStream property for each request before WCF reads it so that it will enforce the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility.
public class WcfReadEntityBodyModeWorkaroundModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context) {
context.BeginRequest += context_BeginRequest;
}
void context_BeginRequest(object sender, EventArgs e) {
//This will force the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility..
Stream stream = (sender as HttpApplication).Request.InputStream;
}
}
Register this module in your web.config by adding these lines in <configuration> <modules> setting.
<system.webServer>
<modules>
<!-- Register the managed module -->
<add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly" />
</modules>
If you are using an app pool in classic mode, you will need to add the module to this section in the web.config:
<system.web>
<httpModules>
<add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly" />
</httpModules>
If your project cannot be modified, then you can write this Http module in a separate assembly, GAC it separately and register this module in the web.config.
Now try accessing the service it should succeed for you!
I have a .NET 3.5 WCF service hosted in IIS. The project service library has an app.config file with some configuration settings (Database connection strings, etc.). I deploy the project via a website project in Visual Studio, which generates a web.config to manage the endpoints. Is there a way I can put the app.config settings from my service library in to the web.config? The IIS hosted service seems to be using default values from the settings designer, and ignoring even an expliclty copied in app.config. I'm guessing this has something to do with the fact that a DLL can not utliize an app.config.
My service application is set up to pull the settings settings from the [MyAssembly].Properties.Settings.Default namespace.
Can you use external configuration files?
Your web.config:
<config>
...
<connectionStrings configSource="myConnections.config"></connectionStrings>
</config>
And then your external myConnections.config file:
<connectionStrings>
<add ... />
</connectionStrings>
You can have multiple external configuration files referenced from your main web.config file. See see this blog post for a nice explanation of how/why to do this.
I hope this helps!
I am developing a custom HttpHandler, to do so I write a C# Class Library and compile to DLL.
As part of this I have some directory locations which I want not hard coded in the app, so i'm trying to put it in the app.config which I've used before.
Before this has worked by just going building the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Share" value="C:\...\"/>
</appSettings>
</configuration>
And then obtaining this in code like:
var shareDirectory = ConfigurationManager.AppSettings["Share"];
But when I compile it and put it in the bin folder for the webservice, it keeps getting null for shareDirectory, probably because it can't find app.config. So how do I make sure this is included so I don't have to hard code my direcotry locations? I notice it will essentially after compiled we get the assembly.dll and the assembly.dll.config which is the app.config file, so it's definetly there in the bin folder!
That is because your web service uses web.config
You're probably confusing the scope of your class library.
Remember, your config, be it web.config, or app.config, is the config present in the HOSTING application. In this case your hosting application is the WebService, hosted of course by IIS, so your config file is the web.config.
If you had a console app which somehow used that class library (though probably not in an http handler context), then the config would be the app.config in the console app, not the app.config in your class library.
You need to put the configuration in your web.config file, not in assembly.dll.config: .NET does not (by design) read assembly.dll.config files.