IBindingConfigurationElement - How to implement and add to configuration? - wcf

I'm trying to extend WCF with a custom binding which has required that I replace message formatting, encoding and security elements within the WCF stack. To facilitate ease-of-use with this binding, I'd like to make it configurable from a configuration file in the same way as the built-in bindings (i.e. a named element, not customBinding).
The WCF standard bindings all inherit from StandardBindingElement, which in turn implements IBindingConfigurationElement. If I implement this interface or inherit from the class, how can I make the configuration element available to the WCF configuration system?

The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/07/26/wcf-extensibility-binding-and-binding-element-configuration-extensions.aspx talks about adding configuration extension for bindings and binding elements, you should find more information there.

I did some digging and found the bindingExtensions element on MSDN. Although the documentation there indicates that you can add bindings this way, I had a peek at my machine.config file and found the following 3.5 bindings registered there:
<bindingExtensions>
<add name="wsHttpContextBinding" type="System.ServiceModel.Configuration.WSHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="netTcpContextBinding" type="System.ServiceModel.Configuration.NetTcpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="webHttpBinding" type="System.ServiceModel.Configuration.WebHttpBindingCollectionElement, System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="basicHttpContextBinding" type="System.ServiceModel.Configuration.BasicHttpContextBindingCollectionElement, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingExtensions>
These classes function as collections of binding elements, inheriting from the odd StandardBindingCollectionElement<TStandardBinding, TBindingConfiguration> class. This looks to be the correct class to inherit from and create an associated StandardBindingElement from.
The collection is registered using the syntax listed above and should then function exactly the same as built-in WCF bindings.

Related

How to configure custom security token handler?

I have implemented custom Saml2SecurityTokenHandler as shown here http://leastprivilege.com/2015/07/02/give-your-wcf-security-architecture-a-makeover-with-identityserver3/.
The constructor of this handler accepts two custom parameters - authority and requiredScopes. In the example this handler is registered in the code. However, I want to do this in web.config file.
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
<securityTokenHandlers>
<clear />
<add type="MyNamespace.MyCustomSaml2SecurityTokenHandler, MyAssembly" />
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>
Is it possible to pass somehow from the configuration (web.config), these two constructor parameters?
give your class MyCustomSaml2SecurityTokenHandler a zero-parameter constructor.
Get those details at run time from your local config on the server side.

Trying to understand System.Web.HttpNotFoundHandler

I need to restrict access to all but one view in my ASP.NET MVC4 project on our public site. We have to prevent a login screen from appears because AD is not setup on our public server as well.
From what I've read about System.Web.HttpNotFoundHandler, the way I understand it is if I include the following line in my web.config all cshtml pages in my /Views folder will be restricted from view:
<httpHandlers>
<add path="*.cshtml" verb="*" type="System.Web.HttpNotFoundHander"/>
</httpHandlers>
However, when I play around with this setting in both of my web.config files, nothing is restricted from view on my local machine when I test. I have my program setup to run on my local IIS7 (our public site is IIS6). I feel I misunderstand how this works.
For IIS 6
<httpHandlers>
<add path="*.cshtml" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
For IIS 7
<httpHandlers>
<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
To deep dive in this topic read This Blog

ReportViewer 10 renders a blank screen when used in ASP.NET application

I have a .NET application written in VS 2010, target .NET version is 4.0, using the ReportingServices version 10 control. My SSRS server is SQL Server 2008 Enterprise. Web Server is IIS 7.5 on Windows Server 2008 R2 64-bit. I did review this question and answer but it did not resolve my problem.
The application has been working fine since August of last year until about a week ago. Of the five reports included in the application, three still work but two have stopped working. When the RS control appears on the screen, I get the message it is Loading with the twirly green circle. Eventually, that stops and all I have left is the control header without a report. I can see the parameters are properly populated and I can click on View Report but I never get the actual report on the screen.
I did go to the Report Manager (SSRS) site and verified the report works as expected. It does take about five minutes to generate, which the users are fine with. They understand it is chewing on a massive amount of data to generate the report. I can't do snapshots since they want the data real-time every time they run it.
I assume there is some sort of timeout, somewhere, but can't find it. One thing I did find is that the Loading message goes away before SQL Server has completed generating the result set for the report, which leads me to believe the timeout is in the application itself. Since other reporting applications on the same web server are working fine (different applications all part of the same web site), I'm not convinced the timeout is there. I did find a Timeout tag for the ServerReport section and set it to a ridiculously high value with no success. I have also re-published both report and application with no success. Code is included below. Thanks for your help in advance!
Relevant code in the .ASPX page:
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer" runat="server" Width="100%"
ProcessingMode="Remote" Font-Names="Arial" Font-Size="8pt"
ShowCredentialPrompts="False" SizeToReportContent="True" ShowParameterPrompts="true"
ShowRefreshButton="True" ShowFindControls="True" ShowPageNavigationControls="true" Height="500px">
<ServerReport DisplayName="Cluster Net Change" ReportPath="/Enrollment Reports/Cluster Net Change"
ReportServerUrl="http://reports.pinnacle.inside.pisd/reportserver" Timeout="6000000" />
</rsweb:ReportViewer>
Relevant sections in web.config:
<assemblies>
<add assembly="System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</buildProviders>
<httpHandlers>
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpHandlers>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>

Accessing Web.Config from a separate solution

I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio 2010.
Thanks
You can put the configuration settings for any library in the main web.config. It's easy!
Connection strings are especially easy. Just add your connection string to the connectionstrings section with the same name it has in the library's app.config, and you're done!
<connectionStrings>
<add name="Sitefinity" connectionString="your connection string"/>
</connectionStrings>
To add configuration settings, at the top of your web config, find the applicationSettings section, and add your section's info. Note: be sure to set your library's settings access modifier to "Public". You can do this in the Properties ui.
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Your.Assembly" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
Then, add the section under applicationSettings.
<applicationSettings>
<Your.Assembly>
<setting name="TestSetting" serializeAs="String">
<value>a test value</value>
</setting>
</Your.Assembly>
</applicationSettings>

Merge wcf app.config with another config file another project?

I have a MyProject.config file that contains ConnectionStrings, AppSettings, and custom sections. I don't want to have to duplicate these settings in the wcf app.config file. Is it possible to merge MyProject.config with app.config or web.config if it is hosted in IIS. If so, where in the code would I do this and how would it be done?
As an example, in MyProject.config, I have a section group called Common and in Common I have AppSettings and ConnectionStrings. I know I can duplicate this in app.config, but then I would have to maintain it in two places.
MyProject.config:
<?xml version="1.0"?>
<configuration>
<sectionGroup name="common">
<section name="appSettings" />
<section name="connectionStrings" />
</sectionGroup>
</configSections>
<common>
<appSettings>
<add key="UserName" value="test" />
<add key="Password" value="test" />
</appSettings>
<connectionstrings></connectionstrings>
</common>
app.config for wcf contains ServiceModel configuration, I dont' want to have to put the above in app.config. I want to read it, does this make sense?
WCF will only load the config based settings for a service from the .NET configuration file for an application (web.config for IIS hosted services). Essentially you are fighting the .NET configuration file model.
If you want to keep the files separate then decide what will act as your primary config file and then use the configSource model for combining multiple config files