archive-be.com » BE » B » BENNYMICHIELSEN.BE

Total: 348

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • wcf – Page 2 – Benny Michielsen
    The framework supported a single programming model long before WCF was available exposing your service was just a different entry in your configuration If you re interested how you need to do this please read my previous blog entries WCF introduced this same concepts to the main Net Framework but also provides a lot of other functionality out of the box Security logging just change some xml tag and you re done I make it sound a bit too easy here figuring out what is wrong in your service section of the app web config is frustrating even with all the tools that are available So what do we need to change in our application to switch from old webservices to the WCF counterpart Well if you ve been following some best practices then your service is already behind an interface and that means the only thing you have to change is the way Spring injects this service in your application public class OrderPresenter IOrderPresenter public IOrderService OrderService get set public IOrderView View get set With the code example above the presenter expects an instance which implements the IOrderService interface it doesn t care if it s WCF asmx webservice or just a local object To add a WCF client object you do not need to change anything in your existing codebase only the way Spring can find the Service you re connecting to as illustrated below object id OrderService type ServiceContract IOrderService ServiceContract factory object OrderServiceChannelFactory factory method CreateChannel object id OrderServiceChannelFactory type System ServiceModel ChannelFactory lt ServiceContract IOrderService System ServiceModel constructor arg name endpointConfigurationName value OrderServiceEndpoint object The OrderService above will be used by my presenter and is created via the OrderServiceChannelFactory Anyone who has some experience with WCF sees that this is just the same as you would do in code when using channels So we re done No not really There is one rather big caveat In the old days my client service reference would still function if there had been an exception For example if the network cable was unplugged and I called a method on the server I d get an exception If I d plug the cable back in and call the method again my client service reference would still function and call the server successfully This is not the case with WCF channels if there is an exception either communication wise like the unplugged network cable or the server throws an exception my client channel will transition in a faulted state Any calls I make on this instance will fail I need a new instance from the channelfactory to get my application going again I could change my presenter to check the service reference but that would mean I need to couple my presenter to WCF and need to add new behaviour This is not something you d want to do I can t get around this problem by normal AOP techniques I can t let the channel check it s own

    Original URL path: http://blog.bennymichielsen.be/tag/wcf/page/2/ (2016-04-29)
    Open archived version from archive


  • Model binding with Headers in ASP.NET WebAPI – Benny Michielsen
    from the header and if it exists return a ValueProviderResult populated with the current values ValueProviders are always accompanied by ValueProviderFactories It s the responsibility of the factory to create and setup the value provider In this case we want to supply our value provider with a reference to the current HttpRequestMessage public class IfModifiedValuesProviderFactory ValueProviderFactory public override IValueProvider GetValueProvider HttpActionContext actionContext return new IfModifiedValuesProvider actionContext Request Inheriting from the abstract base ValueProviderFactory allows us to override the GetValueProvider method where we initialize our value provider We now have enough infrastructure to go back to our AppointmentController public IEnumerable AppointmentModel Get ValueProvider typeof IfModifiedValuesProviderFactory DateTimeOffset ifModifiedSince null IEnumerable AppointmentModel models null using var context new AppointmentsEntities IQueryable appointments context Appointments if ifModifiedSince HasValue appointments appointments Where x x LastModifiedDate ifModifiedSince Value models MapAppointents appointments return models By decorating the ifModifiedSince parameter with the ValueProvider attribute it will be populated with the result of the GetValue call Which does resolve our issue but it would be even better if users of our API would be able to pass the ifModifiedSince date by using the header or supply it via a parameter in the query string There are several ways to make this happen One approach would be to use the ValueProvider attribute again chaining along every value provider we want to use public IEnumerable AppointmentModel Get ValueProvider typeof IfModifiedValuesProviderFactory typeof QueryStringValueProviderFactory DateTimeOffset ifModifiedSince null omitted Adding the QueryStringValueProviderFactory to the list of value providers will help us but every time we want to add another source of our ifModifiedSince parameter we will have to add it here A better approach is to remove the attribute on the parameter entirely and add our value provider to the configuration of our WebAPI public static void Register HttpConfiguration config config Services Add typeof ValueProviderFactory new IfModifiedValuesProviderFactory If we now run the application and use a query string to supply the value for our action we will see that the date is passed along to our controller Unfortunately if a client application uses the header our custom value provider is not invoked at all What s missing Well it turns out that when you declare actions on your controller by default only data that s present in the route data dictionary or the query string will be passed to the controller It s like putting FromUri on your parameters If we want have our own value provider come into play we have to use the ModelBinder attribute as well public IEnumerable AppointmentModel Get ModelBinder DateTimeOffset ifModifiedSince null omitted Now we re telling WebAPI to use the model binding infrastructure The default model binder will use all the registered value providers to create a match Since we ve registered our IfModifiedValuesProviderFactory in the WebAPI configuration it will be automatically picked up If a user of our API uses a query string to pass along the ifModifiedSince value that will keep working as well If we add a CookieValueProvider in the future we will only have to

    Original URL path: http://blog.bennymichielsen.be/2013/11/17/modelbinding-with-headers-in-asp-net-webapi/?replytocom=437 (2016-04-29)
    Open archived version from archive

  • Model binding with Headers in ASP.NET WebAPI – Benny Michielsen
    from the header and if it exists return a ValueProviderResult populated with the current values ValueProviders are always accompanied by ValueProviderFactories It s the responsibility of the factory to create and setup the value provider In this case we want to supply our value provider with a reference to the current HttpRequestMessage public class IfModifiedValuesProviderFactory ValueProviderFactory public override IValueProvider GetValueProvider HttpActionContext actionContext return new IfModifiedValuesProvider actionContext Request Inheriting from the abstract base ValueProviderFactory allows us to override the GetValueProvider method where we initialize our value provider We now have enough infrastructure to go back to our AppointmentController public IEnumerable AppointmentModel Get ValueProvider typeof IfModifiedValuesProviderFactory DateTimeOffset ifModifiedSince null IEnumerable AppointmentModel models null using var context new AppointmentsEntities IQueryable appointments context Appointments if ifModifiedSince HasValue appointments appointments Where x x LastModifiedDate ifModifiedSince Value models MapAppointents appointments return models By decorating the ifModifiedSince parameter with the ValueProvider attribute it will be populated with the result of the GetValue call Which does resolve our issue but it would be even better if users of our API would be able to pass the ifModifiedSince date by using the header or supply it via a parameter in the query string There are several ways to make this happen One approach would be to use the ValueProvider attribute again chaining along every value provider we want to use public IEnumerable AppointmentModel Get ValueProvider typeof IfModifiedValuesProviderFactory typeof QueryStringValueProviderFactory DateTimeOffset ifModifiedSince null omitted Adding the QueryStringValueProviderFactory to the list of value providers will help us but every time we want to add another source of our ifModifiedSince parameter we will have to add it here A better approach is to remove the attribute on the parameter entirely and add our value provider to the configuration of our WebAPI public static void Register HttpConfiguration config config Services Add typeof ValueProviderFactory new IfModifiedValuesProviderFactory If we now run the application and use a query string to supply the value for our action we will see that the date is passed along to our controller Unfortunately if a client application uses the header our custom value provider is not invoked at all What s missing Well it turns out that when you declare actions on your controller by default only data that s present in the route data dictionary or the query string will be passed to the controller It s like putting FromUri on your parameters If we want have our own value provider come into play we have to use the ModelBinder attribute as well public IEnumerable AppointmentModel Get ModelBinder DateTimeOffset ifModifiedSince null omitted Now we re telling WebAPI to use the model binding infrastructure The default model binder will use all the registered value providers to create a match Since we ve registered our IfModifiedValuesProviderFactory in the WebAPI configuration it will be automatically picked up If a user of our API uses a query string to pass along the ifModifiedSince value that will keep working as well If we add a CookieValueProvider in the future we will only have to

    Original URL path: http://blog.bennymichielsen.be/2013/11/17/modelbinding-with-headers-in-asp-net-webapi/?replytocom=449 (2016-04-29)
    Open archived version from archive

  • SignalR, Ninject and WebActivator sitting in a tree – Benny Michielsen
    sometimes the default ConnectionIdGenerator that ships with SignalR was still active I could not really find usefull information on the web and moved code around from WebActivator to the Global asax file and back again Even changing the order of steps that were executed to see if that had any effect but nothing really worked I went back to the Signlar Wiki and reread the page on extensibility and especially the part about changing the DependencyResolver It clearly states that you need to configure SignalR first and ASP NET MVC later A bit more down on the page it s stated that when you want to use another DependencyResolver and if you are using WebActivator you need to wire it up in the PostApplicationStart Clearly there were more moving pieces than I had thought So working with this new insight I removed all MVC configuration code that was in the Global asax file where it happens by default when you create a new project and moved it to a method which I decorated with the PostApplicationStartAttribute assembly WebActivator PostApplicationStartMethod typeof MyNamespace App Start NinjectMVC3 PostStart public static void PostStart GlobalHost DependencyResolver new SignalR Ninject NinjectDependencyResolver bootstrapper Kernel RouteTable Routes MapHubs AreaRegistration RegisterAllAreas RegisterGlobalFilters GlobalFilters Filters RegisterRoutes RouteTable Routes Running the application again clearly showed everything was in the right place now SignalR was now properly configured to use my own Ninject kernel The kernel itself is still being constructed and configured in the PreApplicationStart phase SignalR and MVC are configured in the PostApplicationStart phase Author BennyM Posted on 25 07 2012 25 07 2012 Categories Software Development 1 thought on SignalR Ninject and WebActivator sitting in a tree Kevin says 22 08 2012 at 15 48 Thanks this is just what I needed It was difficult to put all the

    Original URL path: http://blog.bennymichielsen.be/2012/07/25/signalr-ninject-and-webactivator-sitting-in-a-tree/?replytocom=361 (2016-04-29)
    Open archived version from archive

  • Legacy Code Retreat Leuven – Benny Michielsen
    can harvest this kind of information Creating subclasses to override or rather get around methods in order to test which paths the program flow follows is something I had done before Heck you even do that with new code when you re stubbing mocking but we were not allowed to use any sort of framework so we had to hand roll them This eventually leads to a situation where you re testing more the subclass rather then the system under test The answer to that resulting code base is to abstract the code you have to other new classes which are injected through the constructor Typical dependency injection and inversion The last technique was the most eye opening to me It was suggested to make pure functions meaning any method you wrote was not allowed to directly change the object state Somehow I was able to see code duplication and underlying algorithms a lot faster throughout the code base Probably need to look a bit into functional programming as it was quite interesting The last two iterations we were allowed to keep the code we were working on in sharp contrast to a normal code retreat wich gave us some more sense of accomplishment by improving the code base I really liked my first code retreat gave me a change to work with people who work in different parts of the industry embedded programming to name one and from different parts of Europe Looking forward to the next one Author BennyM Posted on 28 11 2011 28 11 2011 Categories Software Development Tags Legacy 1 thought on Legacy Code Retreat Leuven Tim Mahy says 03 12 2011 at 16 56 Probably need to look a bit into functional programming as it was quite interesting damn right Reply Leave a Reply

    Original URL path: http://blog.bennymichielsen.be/2011/11/28/legacy-code-retreat-leuven/?replytocom=263 (2016-04-29)
    Open archived version from archive

  • Benny Michielsen – Page 4 – .net developer with a touch of Cocoa
    find another solution Luckily using the info from my previous post I can write an expression for this var ids new List int 1 2 3 500 using var context new AdventureWorksEntities Expression Func Product bool idMatching null foreach var id in ids int productId id if idMatching null idMatching x x ProductID productId else idMatching idMatching Or x x ProductID productId var products context Products Where idMatching WriteProducts products Author BennyM Posted on 05 12 2010 Categories Software Development Tags entity framework linq 3 Comments on How to support Contains in Entity Framework 3 5 Combining expressions to use with the Entity Framework You often have to create a screen where the information is filtered on a given condition and the user can set some more options through checkboxes For instance display all products of a certain category and those results should be able to be filtered on their active status We could send one query to the database to retrieve the products and then filter them in memory but let s try to use the database for all of this since they re good at this You ll bump into several issues when trying to solve this and like most problems in software development someone else most likely encountered the same issue and has already found a solution In this case take a look at this albeit old article which illustrates the problem and gives a solution It will enable you to write code like this public class ProductFinder public ICollection Product FindProductsBySubCategory int subCategoryId bool makeFlagMarked using var context new AdventureWorksEntities Expression Func Product bool whereClause x x ProductSubcategory ProductSubcategoryID subCategoryId if makeFlagMarked whereClause whereClause And x x MakeFlag return context Products Where whereClause ToList Author BennyM Posted on 05 12 2010 Categories Software Development Tags entity framework linq Leave a comment on Combining expressions to use with the Entity Framework Changing Entity Framework model at runtime Out of the box there is no way or at least not an easy one to change table or schema names used by the Entity Framework at runtime If you used MyDbName dbo BlogPosts as table name during development you can not use MyDbName dbo CustomerA BlogPosts if you want to support customer specific table names as explained in my previous post On CodePlex however you can find an adapter for your Entity Framework model to change it at runtime You can change the connection to the database change table names or use different schemas So a lot of goodness to support multi tenant applications In order to use the adapter you should create a partial class with the name of your context class and inherit from AdaptingContext instead of ObjectContext public partial class AdventureWorksEntities AdaptingObjectContext public AdventureWorksEntities base name AdventureWorksEntities AdventureWorksEntities new ConnectionAdapter new TablePrefixModelAdapter MyPrefix Assembly GetExecutingAssembly OnContextCreated This partial class has the same name as the partial class generated by the Entity Framework You should remove the generated constructors and base class specification from that one or your code will not compile Note that every time you update the model with the designer it will regenerate the constructors etc so you have to remove them every time In this example I m using the TablePrefixModelAdapter which will prefix all my tables with my specified prefix in this case MyPrefix Consuming this context is done just like a normal ObjectContext You also need to specify where the mappings that need to be altered are located in this sample I m using a single console application so they are contained in the executing assembly using var context new AdventureWorksEntities var products context Products products ToList ForEach x Console Write x Name And this generates the following SQL SELECT 1 AS C1 Extent1 ProductID AS ProductID Extent1 Name AS Name Extent1 ProductNumber AS ProductNumber FROM Production MyPrefixProduct AS Extent1 So we re all set to support multi tenancy Not quite The code as available in the CodePlex project stores the updated mappings in a static variable for performance reasons this is great if you re developing against a development database and your code will run against a production database with different naming or schema For a multi tenant application we need a different model for each of our customers so we need to make another change to the code as available in the CodePlex project If you don t mind taking the performance hit to rewrite the mapping every single time an object context is created you can just open the ConnectionAdapter class and change the static variables which hold the model information to instance variables And optimized version would store all the mappings per customer so you only rewrite the mappings once a new customer hits the context and from that point store them in i e a dictionary with key the customerID and value the updated mappings I ve used Entity Framework 3 5 SP1 and Visual Studio 2008 in this post Author BennyM Posted on 05 12 2010 Categories Software Development Tags entity framework 1 Comment on Changing Entity Framework model at runtime Covering multi tenancy in the database You there computer man Make it a multi tenant application There are several ways to support multi tenancy on the database part of your application The easiest approach would be to add a CustomerID column to each table This is easy to maintain since any change you make in your development environment add a column change a type needs to be done only once on the live environment The downside however is that all data of all your customers is mixed in one table forcing you to add a where clause to all your queries to filter on the customer id if you support different business logic per customer you might also run into issues Customer A wants an additional field etc Another approach is to prefix or suffix your table names with some sort of customer identification So you d have CustomerA BlogPosts CustomerB BlogPosts You can

    Original URL path: http://blog.bennymichielsen.be/page/4/ (2016-04-29)
    Open archived version from archive

  • Ms Sql 2000 script for BlogEngine.NET – Benny Michielsen
    1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Reply dhaval parekh says 06 05 2008 at 03 42 Also I copied your script from a Forum post on Codeplex and ran it against the database and it said the following error Please let me know if you have found a solution to this problem Thanks Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 17 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 18 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 8 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 156 Level 15 State 1 Line 16 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostComment because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostComment because this table does not exist in database ccBlog Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostNotify because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostNotify because this table does not exist in database ccBlog Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostTag because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostTag because this table does not exist in database ccBlog Msg 1906 Level 11 State 1 Line 2 Cannot create an index on dbo be PostCategory because this table does not exist in database ccBlog Msg 1906 Level 11 State 1 Line 2 Cannot create an index on dbo be PostCategory because this table does not exist in database ccBlog Msg

    Original URL path: http://blog.bennymichielsen.be/2008/04/03/ms-sql-2000-script-for-blogengine-net/?replytocom=2 (2016-04-29)
    Open archived version from archive

  • Ms Sql 2000 script for BlogEngine.NET – Benny Michielsen
    1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Msg 170 Level 15 State 1 Line 5 Line 5 Incorrect syntax near Reply dhaval parekh says 06 05 2008 at 03 42 Also I copied your script from a Forum post on Codeplex and ran it against the database and it said the following error Please let me know if you have found a solution to this problem Thanks Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 17 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 18 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 8 Incorrect syntax near the keyword PRIMARY Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostCategory because this table does not exist in database ccBlog Msg 156 Level 15 State 1 Line 16 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostComment because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostComment because this table does not exist in database ccBlog Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostNotify because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostNotify because this table does not exist in database ccBlog Msg 156 Level 15 State 1 Line 9 Incorrect syntax near the keyword PRIMARY Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostTag because this table does not exist in database ccBlog Msg 4902 Level 16 State 1 Line 1 Cannot alter table dbo be PostTag because this table does not exist in database ccBlog Msg 1906 Level 11 State 1 Line 2 Cannot create an index on dbo be PostCategory because this table does not exist in database ccBlog Msg 1906 Level 11 State 1 Line 2 Cannot create an index on dbo be PostCategory because this table does not exist in database ccBlog Msg

    Original URL path: http://blog.bennymichielsen.be/2008/04/03/ms-sql-2000-script-for-blogengine-net/?replytocom=4 (2016-04-29)
    Open archived version from archive