Where to configure NLog NHibernate bridge for logging sql configuration? - wcf

As a proof-of-concept I am using a console application wrapping a proxy of a WCF service. I execute a few calls through the proxy and write the results to the console. Underlying the WCF service is a Data Access Layer built on the Repository pattern using NHibernate as an ORM. I want to write the NHib-generated SQL to the console.
I have attempted to configure NLog using the NuGet package and guidance from here with no luck, but I suspect perhaps I don't properly understand where I need to perform these different configuration bits in my many-layered architecture. Here's an attempt at describing my layout:
Solution
|
-- WCF Service
|
-- DAL
| | (NHibernate is used here)
| -- hibernate.cfg.xml
| NLog.config
| App.config (r)
-- WCF Client (console app)
|
--App.config (c)
hibernate.cfg.xml contents:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="show_sql">true</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=AdventureWorks2012;User ID=**;Password=********</property>
</session-factory>
</hibernate-configuration>
NLog.config contents:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="trace" type="Trace" />
</targets>
<rules>
<logger name="NHibernate.SQL" writeTo="trace" />
</rules>
</nlog>
App.config (r) contents:
<configuration>
<appSettings>
<add key="nhibernate-logger" value="NHibernate.NLogLoggerFactory, NHibernate.NLog" />
</appSettings>
</configuration>
App.config (c) contents:
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener" />
</listeners>
</trace>
</system.diagnostics>
<appSettings>
<add key="nhibernate-logger" value="NHibernate.NLogLoggerFactory, NHibernate.NLog" />
</appSettings>
</configuration>
My NUnit unit tests are displaying the SQL Statements, so the show-sql instruction in hibernate.cfg.xml is working correctly. If I insert a Trace.WriteLine() in my console app that shows up in the console, so (I expect) anything written to Trace ought to show up there. But I do not see any SQL in the console.
I'm assuming that I've placed some of my .config instructions in the wrong layers of my app, but where?

Related

system.identityModel not detected in web.config

I have an ASP.NET Core 1.0 project running. When I add the ClaimsPrinciplePermission attribute to my action methods I get the following error when navigating to any action method having that attribute.
An exception of type 'System.InvalidOperationException' occurred in
System.IdentityModel.Services.dll but was not handled in user code
Additional information: ID7024: Use of ClaimsPrincipalPermission
attribute has been attempted and possibly there is no
configuration section defined, see inner
exception for details. Also make sure a ClaimsAuthorizationManager
element is defined under the section.
This is the inner exception
ID7027: Could not load the identity configuration because no
configuration section was found.
This is my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" />
</federationConfiguration>
</system.identityModel.services>
<system.identityModel>
<identityConfiguration>
<claimsAuthorizationManager type="wApp.ClaimManager, wApp" />
</identityConfiguration>
</system.identityModel>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
As you can see, I have added all the required sections. The same code and configuration works well in my MVC 5 projects and also my Web Api project. Is there something different to be done in Asp.Net Core projects?
I have also added the required DLL references in the Core 1.0 MVC project as well duplicated the same configuration sections in the App.config file under the core 1.0 MVC project. Still getting the same error.
What am I missing?
ClaimsPrincipalPermission, and WIF/System.IdentityModel is not part of .NET Core at all. I'm surprised that even compiles.
From the comments it appears you're parsing a JWT, presumably with the JWT bearer token middleware.
So, all identities in ASP.NET Core are ClaimsIdentities. You can go for Simple claims based checks, or, more fully to code expressed policies which give a lot more flexibility.

ServiceStack httpHandlers not loading

BaseLine: ServiceStack sample works for me in a stock MVC 4 app. I am using the variant, followed all the instructions in the readme, no problems.
Plugin Framework
I am building a plugin framework for MVC and servicestack.net is one of the plugins, that being all the assemblies are plugins which get loaded, using BuildManager.AddReferencedAssembly(assembly);
BuildManager.AddCompilationDependency(assembly.FullName);
All the ServiceStack dlls are found and successfully loaded from my personal shawdowFolder.
webconfig:
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory,ServiceStack" verb="*" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory,ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>
*NOTE: I am calling from Application_Start AppHost.Init(), and I can step it so ServiceStack is truly loaded and usable before the ASP.NET app goes into full swing.*
On first launch: /api/metadata results in:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /api/metadata
Stopping the debugger and simply relaunching, which deletes all assemblies from my personal shawdowFolder, copies them, loads them, references them, results in.
A working ServiceStack.net
StarterTemplate ASP.NET Host
The following operations are supported. For a formal definition, please review the Service XSD.
etc.
I suspect that this problable has to do with .NET's shadowfolder and appdomain, but perhaps it is something with ServiceStack. Where would I find logs to see if ServiceStacks httphanderfactory is having problems.
I Changed my config as follows :
SetConfig(new EndpointHostConfig
{ ServiceStackHandlerFactoryPath = "ss"}
and my config :
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
<add name="FormsAuthenticationDisposition" type="ServiceStack.ServiceInterface.SuppressFormsAuthenticationRedirectModule, ServiceStack.ServiceInterface" />
</modules>
<handlers>
<add type="DevExpress.Web.ASPxUploadControl.ASPxUploadProgressHttpHandler, DevExpress.Web.v13.1, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
<add path="ss*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" /></handlers>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
</requestFiltering>
</security>
</system.webServer>
Now I have to type in the following to get to my servicestack area : http://localhost/ss/
My take on what is going wrong is that mvc/asp.net forms/ servicestack each needs one entry point to map its handler to an url route, servicestack is overriding the url route for "/" your MVC project hence no resources is found.
Thus in my application I used to seperate entries points:
*http://localhost/* .... is my normal entrypoint for webforms (in your case MVC4[stock])
http://localhost/ss .... is my servicesstack entrypoint
If you are using the MVC razor engine you won't run into this.

Private NuGet Server: Request Entity Too Large

We have a internal NuGet server (ASP.net app using the NuGet.Server package) and we want to use it with Octopus to deploy packages. So the first thing you hit is that the packages are too large.
When you push a package larger than around 7 Meg you get:
Failed to process request. 'Request Entity Too Large'.
The remote server returned an error: (413) Request Entity Too Large..
Based on the documentation on Octopus, I updated the web.config file to have the changes.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/>
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
</httpModules>
<httpRuntime maxRequestLength="419430400" executionTimeout="3600"/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler"/>
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler"/>
</modules>
<staticContent>
<mimeMap fileExtension=".nupkg" mimeType="application/zip"/>
</staticContent>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="419430400"/>
</requestFiltering>
</security>
</system.webServer>
<elmah>
<security allowRemoteAccess="false"/>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data"/>
</elmah>
<location path="elmah.axd" inheritInChildApplications="false">
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode"/>
</handlers>
</system.webServer>
</location>
<appSettings>
<add key="apiKey" value="KeyHere"/>
<add key="packagesPath" value=""/>
</appSettings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
</configuration>
That does not work. Other posts talk about running something like (IIS7):
appcmd.exe set config -section:system.webServer/serverRuntime /uploadReadAheadSize:"419430400" /commit:apphost
or (IIS6):
cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 419430400
I tried both to no avail. Neither command returned an error, so I assume that the value '419430400' is correct for all of the calls (bytes vs. some other unit of size).
Anyone have any idea what I am missing?
I ended up just copying the package to a share on the web server, but I would really like the push command to work.
Not exactly answering the OP's question, but related to the topic, I was getting the (413) Request Entity Too Large error while using NuGet push to push to a local SymbolSource server - turned out I was submitting to a slightly incorrect URL, once I corrected the command to point to the base /NuGet/ URL, it ran just fine.
No idea why an incorrect URL results in the 413 error, but there you go. Hope this helps someone.
EDIT: based on comments below, you may have more luck just referencing the base http://www.myserver.com/ URL rather than including the /NuGet as well. Worth playing around a bit.
I know this is an old question, but today I was faced with the same error. It's worth noticing that I'm using TeamCity package building and publishing. Anyway, when I try to Publish my huge package (about 200 MB) I was blocked with this. The solution was simple:
Instead of publishing to http://mynugetserver/api/v2/, use: http://mynugetserver/
You'll have to set these guys to higher values:
system.web - httpRuntime - maxRequestLength to, say, 1048576
system.webserver - security - requestFiltering - requestLimits -
maxAllowedContentLength to, say 1073741824
Both values are in a different unit so the second one should be larger than the first.
Also, have a look at www.myget.org which I found great when working with Octopus Deploy.
Check your serverRuntime configuration.
The maxRequestEntityAllowed and uploadReadAheadSize attributes respectively configure limits for the maximum number of bytes allowed in the entity body of a request and the number of bytes a Web server will read into a buffer and pass to an ISAPI extension.
More details: http://www.iis.net/configreference/system.webserver/serverruntime
My guess is that you are using SSL and setting uploadReadAheadSize will solve the issue. Because during client renegotiation process,the request entity body must be preloaded using SSL preload. SSL preload will use the value of the uploadReadAheadSize property, which is used for ISAPI extensions.
Here are the defaults
<location path="Default Web Site">
<system.webServer>
<serverRuntime enabled="true"
uploadReadAheadSize="49152"
maxRequestEntityAllowed="4294967295" />
</system.webServer>
</location>
Based on #Keith and #Nubigetter's answers, I did some further research, because the behavior seemed really weird to me.
The answer is actually in the documentation for Nuget.Server (if you look very carefully), it's just not very obvious:
use http://mynugetserver/nuget for list/restore
use http://mynugetserver/ for push
I've raised this with the Nuget team here https://github.com/NuGet/NuGetGallery/issues/2903 because I regard this behavior as 'presenting opportunity for improvement'.
This is due to nginx limitations, the nuget server in Linux system use nginx as proxy and config file under:
/etc/nginx/conf.d/nuget.conf
server_name localhost;
root /var/www/public/;
client_max_body_size 200M;
change client_max_body_size 200M is working for me.
I had the same issue:
[Step 1/2] Publishing package to feed at http://localhost/OctopusDeploy/nuget/packages...
[Step 1/2] Failed to push to package feed at 'http://localhost/OctopusDeploy/nuget/packages/'.
[Step 1/2] (The server responded with: [413] Request Entity Too Large)
[Step 1/2] Process exited with code 1
but the Octopus Deploy service had stopped!
What worked for me was in this article:
http://blogs.blackmarble.co.uk/blogs/rfennell/post/2012/10/31/403-and-413-errors-when-publishing-to-a-local-Nuget-Server.aspx
"Important: This second error was a red herring, you don't need the /nuget on the end of the URL"

NServiceBus: Trouble getting PubSub working with Distributor

I'm using NServiceBus 2.5 and trying to get a simplified version of the NServiceBus PubSub sample working with the distributor. The simplification:
1 Publisher
Distributor
1 Subscriber
All of this is on a single machine.
I would like to get this working before I move on to more complex things like multiple subscribers behind a single distributor, multiple machines, etc.
First I got the simplified pub sub example working without the distributor (i.e 1 pub and 1 sub - and I got that working fine).
As I understand it, the way it should work is:
The distributor defines its own control and data queues.
The publisher has it's control queue, but no other config refers to this queue. The publisher refers to the distributes data queue.
The subscriber refers to the distributors data and control queues.
I've not been able to get the simplified pub-sub distributor working with this config. I've done some debugging of the publisher and what I've found is that the publisher's Bus.Publish doesn't find any subscribers to publish to.
Any ideas what I'm doing wrong and what I need to do to get this working?
Here's configs for each of those:
Publisher:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig InputQueue="MyPublisherInputQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="MyMessages" Endpoint="distributorDataBus" />
</MessageEndpointMappings>
</UnicastBusConfig>
</configuration>
Distributor
<add key="DataInputQueue" value="distributorDataBus"/>
<add key="ControlInputQueue" value="distributorControlBus"/>
<add key="ErrorQueue" value="error"/>
<add key="StorageQueue" value="distributorStorage"/>
<add key="NameSpace" value="http://www.UdiDahan.com"/>
<!-- relevant for a Serialization of "interfaces" or "xml" -->
<add key="Serialization" value="xml"/>
<!-- can be either "xml", or "binary" -->
</appSettings>
</configuration>
Subscriber
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig
InputQueue="Subscriber1InputQueue_1"
ErrorQueue="error"
NumberOfWorkerThreads="1"
MaxRetries="5"
/>
<UnicastBusConfig DistributorControlAddress="distributorControlBus" DistributorDataAddress="distributorDataBus">
<MessageEndpointMappings />
</UnicastBusConfig>
</configuration>
Ok, I finally got this working. The key clue came from here: http://tech.groups.yahoo.com/group/nservicebus/message/8525
Basically, the subscriber needs to be pointed to the publisher by adding this section:
<UnicastBusConfig DistributorControlAddress="distributorControlBus" DistributorDataAddress="distributorDataBus">
<MessageEndpointMappings>
<add Messages="MyMessages" Endpoint="MyPublisherInputQueue" />
</MessageEndpointMappings>
</UnicastBusConfig>
I initially thought that this is making the subscriber register directly with the publisher, but no. I tested that out with two different subscribers pointed to the same distributor and noted that only one of the subscribers gets any single event published.

How to debug a WCF service connected with multiple clients - .NET

I've written a WCF service with a duplex contract which asynchronously calls back the clients. I have some issues when multiple clients get connected and i dono how to debug the service. Any insights on this?
Thank you.
NLV
A bit more info on what your problem is would be helpful, but to get you started try enabling diagnostics. Add the following to your service config and set "initializeData" to set where the log file is written. Opening the file should launch Microsoft Service Trace Viewer. You can do the same on the client side. If you have both a service log and client log in Trace Viewer go to Menu -> Add and select the other file. You will then get the message interactions matched up in the graph tab.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Verbose">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="D:\wcfLog.svcLog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
More info here: Tracing