Monday, December 1, 2014

Adding SOAP prefix to ASMX service using SOAP extensions

Just a preamble here I received the requirement from a third party vendor to add a specific prefix to my soap response. Even know in XML these two formats are equal.

I was required to add it regardless because I assume they were parsing this manually with java or some other client. I came upon these two articles by one of my favorite developers/bloggers Scott Hanselman really the basis of everything I've done here so here is credit where it is do.

Modifying the namespace PREFIX of the root node of the body of a SOAP Web Services Response....whew!
[XmlRootForcePrefix(Prefix='foo')

He apparently ran into the same exact issues with a client who was not satisfied with the soap response he was giving them even know it was exactly the same as the one they were requesting. Anyone that makes you add a prefix to your soap response is probably doing something terribly wrong at the risk of my soul going to hell I was not about to email Scott to confirm the fact I am a scrub and indeed was in need of a fix I did some research and was able to create my own implementation. ***WARNING DO NOT USE UNLESS YOU ARE BETWEEN A ROCK AND A HARD PLACE GO WCF INSTEAD***

First you will want to register the soap extension in your web.config file under the system.web tag as follows:

Just replace the items accordingly and know your assembly file name is most likely your project name if your project is named test then test is your most likely candidate.

Here is the code and once again credit to Scott Hanselman because I used another article he wrote for the implementation of removing white spaces to write this extension with some minor changes in naming convention and the addition of serialization to the xmldocument object and then writing it back to the response stream.

Last of all just add the attribute to your webmethods that you would like to use this prefix on. [Prefix] also make sure you are referencing System.ComponentModel.DataAnnotations

Hopefully this helps some poor guy out there that has been put in a hard spot like myself last week. I could not find anywhere this information was in one place and was accessible.

Wednesday, May 28, 2014

JavaScript - Chapter 1 - Basics

JavaScript - Chapter 1 - Basics

Back again for some more fun with JavaScript. I will eventually lead this conversation into a website project and maybe some off shoots into areas of gaming or server scripting. However before you can run you must first learn to walk so here we are. There are some basic things you must know about any programming language there are rules and syntax that the interpreter understands and if you break these you will not have a functional program. Everyone assumes to be able to program you need to be good at math. I received my bachelors degree in Mathematics and my master's degree in Information Systems. However useful the math is for logic and data I've found programming more suited to learning a new language.

Types

There are five primitive data types in JavaScript and they are as follows:

There are other types that are objects, arrays, and functions. Objects are used to hold data as properties as well as perform tasks via defined functions when they are attached to an Object most refer to them as methods. Arrays also hold data but that is their main purpose. Function executes a snippet of logic takes parameters and usually returns values.  Here are a few examples of the more complex types as follows:




Comments

There is some debate on whether you would want to use comments in code at least a few articles I have read lately they debate that well written code needs not to be cluttered with comments. I myself find them very useful. If you have a complex piece of code you would want other developers to know what a certain section of logic does especially when you are using shortened naming conventions as is common in JavaScript to keep payload down. Here are examples of how to use comments and you will notice up above I have already left a few in prior examples. 



Keywords

There are a few words that are not allowed to be used as literals in your syntax because the interpreter regards these handful of words to perform operations. An example would be a variable. Just like your college algebra class you had to solve the following equation x+ 4 = 8 so here naturally x would be equal to 4 to complete the expression. In programming we have placeholders such as x to hold values or objects these are called variables. A variable definition would go as follows in the code:

var x = 4;

Here we are declaring a variable name x and it hold the value 4 which can be reused or reassigned throughout the code. The var portion of the variable declaration is a keyword. The interpreter knows that following the var keyword an a variable name then after and equal sign knows that a value is going to be assigned to the variable which has been declared. Here are some more keywords that are worth noting I would recommend visiting the following link for the functionality and definitions of what these key words do.



Your First Program

First we need to have a place to write and execute our code luckily with JavaScript we will not need expensive IDE just need to install Firefox.

Download Firefox


To open a scratch pad just click on the orange Firefox menu in the top left corner of the browser and then select Web Developer = > Scratch pad

This will allow you to write some basic JavaScript then execute it in the browser. Here comes the boom first program that every developer needs to write is the "Hello World!" program so in your scratch pad perform the following:

You will find that this opens in the browser and congratulations you are starting to code like Vikings. I'll catch you next week with some more fun. 






Tuesday, May 20, 2014

Javascript - Intro

Javascript - Intro

So in development right now there is a movement. It appears to me at least  that there are hordes of developers moving their shops over to javascript (JS).This  I suppose is due to there being better options for organizing the code and how client side code is able to communicate with the server.  You have new JS frameworks that create MVC structure for your web-based projects and along with that you have restful web-services that return Json that seems like a perfect marriage for JS to move and display data. Now we are going so far as to actually program your server in JS and complete the full request cycle without deviating from the JS. You could also embrace technologies that stored your data in JS type objects and  you can kiss SQL traditional data storage goodbye as you embrace this new form of development. I currently work for a Microsoft shop and have worked a little bit in JS. I have seen the brutal nature of scripts that go on for days and have very little structure. I once chased an error for two weeks before realizing that it was an extra comma in a 2000 line JS file that had been left there by accident from a previous cohort. I have rendered large amounts of data using every Jquery plugin under the sun.  But where I have lacked knowledge is good OO methodology for building scalable and maintainable JS projects. So I decided to start from the start and relearn JS from the very foundation. I'm hoping to go over the entry items and with weekly post work my way into a full website example. This is mostly something I promised a couple of friends of mine they wanted to learn how to code. I find to as I put my thoughts out here for the world I try to make them more meaningful and in doing so I feel educated personally by doing this so hey win, win.


So this next section is a rundown of what I personally know about JS off the top of my head. I'm sure I'm going to leave a few things out my apologies. I don't claim to be awesome just another scrub trying to earn a buck for his family who needs new shoes and electronics. So now that the disclaimer is out of the way lets talk techy for a bit.

Javascript(JS) is a interpreted language what does this mean it means that it is ran directly as is and is not compiled before hand into a language the the computer understands. It is supported in all browsers and the engine the interprets and executes JS code has made some major jumps in the last few years which also is probably why it's becoming a more feasible solution.

There are drawbacks for interpreted languages mostly they are slower then compiled languages and the big one is they are not checked for errors during compiling to avoid pitfalls. If you make a mistake in JS it's going to show up for your users so testing becomes key and most of all organization like the instance I mentioned earlier if you mess up your markup you may be on a hunt to find where the issues reside. I've heard that the syntax of JS was influenced by Java but don't be a noob and tell people (especially techy folk) that you are writing Java as I have heard many a person say then to my chagrin find them writing JS. However the good news is now you can tell your peeps you are a Javascript Developer and they think you are the man and shoot lightning bolts from your backside like William Wallace.


Javascript is a un-typed language I have also heard the term loosely type language meaning that you do not have to strongly type your variables before you assign them and also you have the flexibility to use a variable for one type here and then assign a different type down the road and hopefully you can see by this statement alone why this can be troublesome and why not being frivolous with this power is vital to keeping maintainable code.

So that is what I have for now buckle up next week I'll start going over the types and assigning variables. Then onward and upward. Remember to code like Vikings. :D



Tuesday, May 6, 2014

Chrome Auto Fill Honey Pot Hack

So today I have to say chrome actually is making me a bit heated. It's like my child that is always my good one just decided to go bad to get some attention. I still love you chrome but here we go. Today on my website I have a settings page where the user can update their username and a new password. If the user however has chosen to save password information upon login you get these very non stylish yellow boxes.

So I was thinking about my current research on honey pots to stop bots from autofilling your username and password fields and I thought why not stop the chrome monster from doing the same thing to my settings page. It's ironic that I'm using hacking prevention to fix an issue with chrome. So here is an easy fix for the man that doesn't want the tacky dom load change.

Place an input above your other fields you do not want filled.

Set the style to display none and the end user will not ever know it's there. Also no yellow boxes. This may not be the most eligent fix but I thought I would throw a twist on the posts I saw out there already.

The result:

I should also throw some credit to Phil Haack who's article I was reading to try to replace my captchas.

Tuesday, March 25, 2014

Adding Bootstrap Classes to MVC @Html elements

Just started a project at work building an employee management website with MVC4 and I'm really impressed so far with what I've seen very good product from Microsoft. Later on I'll supplement this blog with a full website example in MVC4 also I have toyed with a series on WCF web services which are my forte at the moment I have written quite a few webservices using the WCF technology and have learned some cool tricks but back to the matter at hand.

I started this new web project using twitter bootstrap I've been primarily a backend guy and twitter bootstrap really makes sense for me. I hate dealing with custom styles and building the foundation CSS tools that I need to make my website Twitter bootstrap gives you all those tools right out of the box. No more worrying about layout and disign or dynamic layout it's all included and with the following tools you can build a template and just include it in your project and the bulk of your CSS is done.

So once you add these style sheets and a jquery reference how do we add these styles to our MVC4 elements? Well it's actually quite easy. First thing you must know when you are using the MVC4 @Html elements they take parameters. The first specifies a binding to your Model object you will see this association threw a lamba expression depending on which element you are currently using. Then you have some controller options if the element is an action element such as a link that redirects to another page. After that these element take a generic object for a parameter and that is where the magic happens. There you can access all the attributes of the DOM including the style class.

Here are a couple of examples:

So you can see here in the first example this is an action controller that redirects the the "Alerts" method on the "Dashboard" Controller and the value of my link is "Alerts" as well this is what will show up on the page. Also I added the boostrap classes for the button so this link should look great when it renders on the page.

So the second example same story also you will see that I added a water mark to the text box as well. So you can see all attributes are accessible. So when I stack a few of these links I can make a nice little menu.

Here is my textbox with the water mark:

I really hope this helps someone else out mostly I keep this blog so when I forget something I've learned I can come back and check it out save some time. Hope this also saves other developers time as well. Remember to code like vikings!!!

Wednesday, March 5, 2014

Jquery Change CSS upon table value

I was just checking out stackoverflow there was a chap on there that was trying to change the css of a table based on the value of the content. I remembered doing this on a company website so to archive it and to help others here is the simple solution I came up with to accommodate the requirements.

So the gist of this code is there is a style class that has been assigned in the header. There is a snippet of code in jquery that is where the magic happens. I select all the table elements by class you could also just select on the basic element td but in this case I went for a more practical approach since most likely you are not going to want to change css for every td on the site but who knows maybe you do. More power to you my friend. I use the each function to step through the different jquery objects in the array. For each object I pull the value and if it's negative I assign the class. It's really simple straight forward. I hope this helps someone and saves them some time.

Thursday, February 27, 2014

Window's InputSimulator Radio Button Check

Just another day another learning experience. I was asked by my employer to write a selenium script to import about 2000 data entries into a web portal. This was the first selenium script I have wrote and with help from a colleague that works with selenium daily I was able to accomplish this task.

First the Dependencies:

WindowsInput
Selenium


WindowsInput is a dll you can paste and reference in your bin a short google search should yield results for this  so I won't go to any detail unless someone requests it then I'll do a follow up post. Selenium and be installed via the Nuget Manager within Visual Studio which is a blessing from heaven no more searching around the web for what you need.

So here is my little method which is more just to display some of the options that I used to write my script. The comments are self explanatory this is a very basic implementation. You will notice the ability to navigate to a url. My experience included adding logic for basic auth before I was able to put any input in the forms.


So what I wanted to throw out here in this blog post was the simple fact that I hunted around the web for  about 40 min trying to find how to check that lame radio button on the import form. I could get the focus on the radio button but I was unaware that there was any keyboard stroke that could fill that puppy in. Where the limitations are that I could not use the mouse buttons I had to find and alternate way of doing this. I finally ran across this page from Mozilla which is awesome because I'm writing this script in Firefox there are ways of using other browsers as well. 

Mozilla Forum


So there I learned that you could turn a radio button on or off by selected the spacebar. So as you can see in my code the last simulation is the space which selects the radio button, the rest of my data fills and the submit button selected and all is right in the world. I just thought I could maybe save someone else the same 40 minutes our time is precious. Also maybe this is just common knowledge let me know if I'm super lame and I was living in ignorance. Thanks. Remember to code like Vikings.

Wednesday, February 26, 2014

Report Viewer Control IE11

With the latest release of IE11 there have been some cool upgrades I would say in style of the dev tools (it would be cool if they did not time out on me) but there are some compatibility issues that I have ran into with a ReportViewer control on my web application. Each time I would try to render a .rdl file document via the controller the loading .gif would kick on and the report would time out on me. It appears I was not the only one.

Web Forms project
Server: IIS7 
Framework: 3.5
Microsoft Report Viewer 10.0.0.0
Visual Studio 2012


So searching around the web I found the usual suspects the first thing everyone was shouting on stack overflow was changing the rendering of IE to IE10 mode via meta tags in the head of the document. I'm not really a fan of this approach it's more of a band-aid solution then a fix. 

Then I tried using the dev tools on IE11 to see if I could narrow down the network traffic and see which requests were timing out and received no joy there. 

Finally I found the clue I was looking for to break this issue. I ran the request again while logged into the web server and checking the Event Viewer log. There I saw my failed attempt to pull the document. The event viewer logs read "HttpHandlerInputException, Missing URL parameter: IterationId."

After some searching I found that you could fix this missing parameter by adding some logic to your gobal.aspx file on your project as follows: 


It basically checks your request and if it is coming from your report viewer url performs another check to make sure that the parameter has a value and if not places the default zero value which will suffice the request and you will get your document. Experimenting with this issue I only found it in IE11 with the rest of the browser the rendering without this parameter was not an issue. It seems that IE is a little more picky on what it will allow to come through the system. I've found this with the rendering of CSS and html as well. I hope this post helps someone out there save some time. This was a 2 day easter egg hunt for myself. Always looking to pass this information along to my fellow coders. Also I've using this blog to document my fixes so later on when I run into this again I'll know where to start.