Huge amounts of data WCF \ Silverlight

18. March 2011 04:03 by Mrojas in General  //  Tags: , , , , , , ,   //   Comments (0)

 

Today I found this excellent post:
http://smehrozalam.wordpress.com/2009/01/29/retrieving-huge-amount-of-data-from-wcf-service-in-silverlight-application/ 
and I was the key to solve a problem I had with a WCF service.

I had made some changes to an application to send a text file to the server
for batch processing, everything was working fine until I started sending big files.

I just received one of those obnoxious Not Found error.
So what could I do? Well as any respectable WCF developer would I started tracing the WCF messages with Fiddler, and I found this:

If you cannot read it from the image the message was:

DeserializationFailed… The formatter threw an exception while trying to deserialize the message:
There was an error while trying to deserialize parameter :_xxxxxx.
The InnerException message was 'There was an error deserializing the object of type System.String.
The maximum string content length quota (8192) has been exceeded while reading XML data.
This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas
object used when creating the XML reader.

I was a little confused but thanks to that post I was able to just add:

          <binaryMessageEncoding maxWritePoolSize="16" maxSessionSize="8192">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                                   maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </binaryMessageEncoding>
 
 

And got everything working again!

Doing Backups in Windows Azure

17. March 2011 03:47 by Mrojas in   //  Tags: , , ,   //   Comments (0)

When we migrate our customers to Azure, we want them to take advantage of
this rich platform.

Even for a simple deployment you get a Windows Azure Storage Account,
and that account means up to 100TB of storage!!!!! So take advantage of that.

One common thing that any enterprise needs is backups.
You need to backups of you email files, databases, documents, etc.

Sometimes you can have a dedicated server for storing that data, but
all hard drives can fail, so you will need to make several copies of your
backup information, probably use a RAID disk, make backups of your backups
on tape, DVD, etc…

What if you could just use your cloud storage, which is triplicated in secure datacenters?

Well you can!

There are currently several solutions.

For example in codeplex you will find projects like: http://myazurebackup.codeplex.com

MyAzureBackup provides simple to use web user interface.
I have even extended some of its functionality to work with a Windows Service that uses
a FileWatcher to upload files from a directory.
And it is easy to use this application as a base for your backup infrastructure adding some
security functionality like encrypting files.

So go ahead and explore all the new posibilities you have with cloud computing

Tracking Bugs in Windows 7

11. March 2011 04:05 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

Is very common that a user calls you to report a bug,
but it takes you a long time to understand what really happened.

Well Windows 7 has a great tool call the Problem Step Recorder.

This post will provide a good intro using this tool: http://www.blog.jbi.in/tipsntricks/how-to-use-problem-steps-recorder-in-windows-7/

 

 

Azure Migration: ASP.NET Site with Classic Pipeline mode

Recently while we were performing the migration of a blog engine in ASP.NET to Azure we had to deal with some issues with
the differences between IIS6 and IIS7.

Windows Azure Web Roles, use IIS7, with Integrated Pipeline mode and that is a breaking change for some ASP.NET sites.

The are at least two main changes:

 

First  is for HTTP modules and handlers.(This info was taken from: http://arcware.net/use-a-single-web-config-for-iis6-and-iis7/)

" For IIS6, they were configured in the <system.web> section, as such:

 

        <httpModules>
            <add name="..." type="..." />
            <add name="..." type="..." />
            <add name="..." type="..." />
        </httpModules>

        <httpHandlers>
                 <add  verb="..." path="..." type="..." />
                 <add  verb="..." path="..." type="..." />
        </httpHandlers>

However, to get these to work in IIS7 you must *move them* from the <system.web> section to the new <system.webServer> section, which is what IIS7 requires when running in Integrated Pipeline mode (it’s not needed for Classic Pipeline mode)

 

So instead of the above you have this instead:

<system.webServer>
    </modules>
        <add name="..." type="..." />
    </modules>
    <handlers accessPolicy="Read, Write, Script, Execute">
        <add verb="...." name="..." path="..." type="..." />

</handlers>
</system.webServer>

Notice there are a couple slight changes, which means you can;t just copy and paste
these as-is from <system.web> into <system.webServer>:

<httpModules> and <httpHandlers> have been renamed to <modules> and <handlers>, respectively.

Each handler in IIS7 requires a name attribute. If you don;t specify it, you'll get an error message.

The handlers node has an optional, but good-to-define accessPolicy attribute.
This value depends on your handlers, so use the ones that are right for you."

Second
There are some restrictions in IIS7 when you are running in Integrated mode.
For example you cannot do calls to the request property of an HttpContext object.
All calls to HttpContext.Current.Request will have a problem because Request will be null.

You can see more details here:

http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

 

Coldfusion cfdocument bug with images and Windows Authentication

4. March 2011 16:52 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

If you are running your Coldfusion Server with IIS7 and you use Windows Authentication you should be aware that you might
encouter a bug if you try to use a cfdocument tag like:

 <cfdocument format="pdf">

Hello World <img src="images/world.png">

</cfdocument>

The problem here is that Coldfusion will use http to get the image when building the PDF, and because this site uses Windows Authentication it crashes.

How to solve it?

 <cfdocument format="pdf" localUrl="true">

Hello World <img src="images/world.png">

</cfdocument>

This solves this bug and also improves perfomance because CF will convert images/world.png to a physical path like file://E:/images/world.png

Running Coldfusion on a Web Server Role

4. March 2011 15:43 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

I have been playing around with one of my test Azure Web Roles to determine
if it is possible to run it inside Azure, using a Web Role not just a VM Role.

So far I have been able to run Coldfusion 8 in a Web Role, but I have not been able to fully automate this task,
I had to do a remote desktop to the Web Role and perform the following tasks:

  • Add Features to the Web Roles particulary II6 Management Compatibility
  • Make sure that the Handlers for CFM, CFML, CFC are inplace

IIS Handler CF

  • And make sure that the ISAPI is ok:
  • Once all that is set you can run Coldfusion 8 in your Web Role. Now we just need to automate all the CF8 installation in a Web Role,
    but that will be something another post

 

Control Property Serialization in .NET

While solving a bug with a custom class that extended the System.Data.DataSet class, I found a situation where the class implemented, the ISerializable interface, but for some reason, during the call to the base.GetObjectData in my serialization code it was trying to get the value of some properties that caused an exception.

The reason was that those properties were not “ready” because my serialization code had not finish initializing the object. But why was the Dataset.GetObjectData trying to get or set those values.

It seems that there is some code in the dataset that used reflection to get the object properties and try to serialize them. I did not want that.
How could I stop the framework from doing that?


I thought of the NonSerializable attribute but that works only on fields and what I have is a property.

I thought of the XmlIgnore attribute but it had no effect.

Why!!!!

Well I finally found that you can add a couple of (not attributes) methods to your component.

They should be named Reset<Property>() and ShouldSerialize<Property>() and returning a boolean value
from these functions will control if the properties are serialized or not.

For more info see MSDN page for ShouldSerialize

Problems installing the Windows Phone 7 Tools

1. March 2011 04:18 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

If you are getting ready to migrate your applications to Windows Phone,
you have to install all the neccesary Windows Phone Stuff.

However you might have incompatibilities in your dev machine.

This post: http://blogs.msdn.com/b/astebner/archive/2010/07/12/10037442.aspx

Is great. I used it to identity why the installation tool insisted that
I had a Windows Phone Emulator installed in my machine. It seems that it looked for something like XDE.

So if you have this same issue or something similar just take a look at that post, it might be of great help

ASP Migration COM+ and security

18. February 2011 02:53 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

Typical ASP applications were built as a layer of simple ASP with some
COM+ components that did the heavy lifting.

Now, when you migrate your ASP application to ASP.NET and you also migrate your
COM+ components to .NET then you might encounter some issues with security.

One common issue is impersonation.

Sometimes the COM+ were created to use the current user account.

clip_image002

 

clip_image002[6]

And there is a slight 
difference between ASP and ASP.NET:

“Impersonation is when ASP.NET executes code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account. This is contrary to the default behavior of ASP, which uses impersonation by default. In Internet Information Services (IIS) 6, the default identity is the NetworkService account.”

That will cause errors in your ASP.NET application like:

 

clip_image002[8]

To solve this issue you must use ASP.NET Impersonation, and to enable impersonation go to the web.config file and add:

<identity impersonate=”true”/>

For more info on impersonation see: http://msdn.microsoft.com/en-us/library/aa292118(v=vs.71).aspx

Problems Debugging Silverlight with VS 2008

31. January 2011 10:58 by Mrojas in General  //  Tags: , ,   //   Comments (0)

If for any reason you have to debug and develop Silverlight VS 2008,
and you encounter a problem that when you start debugger it reports
something as if the version you have is not supported then first do this:

Open regedit and check:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Silverlight\Components\Debugging\Value

A Version value of 4.0.50917.0 means that you have the Silverlight 4 Developer and you need to:

1. erase this entry.

2. Uninstall Silverlight 4 Tool

3. Reinstall Silverlight 3 Tools for Visual Studio 2008.

IIS targetFramework not supported

31. January 2011 10:55 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

 

I had a situation where the IIS reported that the targetFramework=4.0 attribute
was not supported.

I’m not sure why it started reporting it, but I fixed it with this:

%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i

Restoring simple lookup capabilities to Silverlight ListBox

27. January 2011 04:09 by Mrojas in General  //  Tags: , , , , , , ,   //   Comments (0)

VB6 and WinForms ListBox has the built in capability to provide a simple data look up. But the Silverlight ListBox does not.
So if you have a list with items:

Apple 
Airplane 
Blueberry 
Bee 
Car 
Zoo 
Animal Planet

And your current item is Apple when you press A the next current item will be Airplane

Apple 
Airplane 
Blueberry 
Bee 
Car 
Zoo 
Animal Planet

And the next time you press A the next current item will be Animal Planet

Apple 
Airplane 
Blueberry 
Bee 
Car 
Zoo 
Animal Planet

And the next time you press A the next current item will be Apple again

Ok to do in Silverlight you need to add a event handler. You can create a user control and this event handler and replace your listbox for your custom listbox or just add this event handler for the listboxes that need it. The code you need is the following:

void listbox1_KeyDown(object sender, KeyEventArgs e)
{
    String selectedText = this.listbox1.SelectedItem.ToString();
    String keyAsString = e.Key.ToString();
    int maxItems = listbox1.Items.Count;
    if (!String.IsNullOrEmpty(selectedText) && 
        !String.IsNullOrEmpty(keyAsString) && keyAsString.Length == 1 && 
         maxItems > 1)
    {   
        
        int currentIndex = this.listbox1.SelectedIndex;
        int nextIndex    = (currentIndex + 1) % maxItems;
        while (currentIndex != nextIndex)
        {
            if (this.listbox1.Items[nextIndex].ToString().ToUpper().StartsWith(keyAsString))
            {
                this.listbox1.SelectedIndex = nextIndex;
                return;
            }   
            nextIndex    = (nextIndex + 1) % maxItems;   
        }
        //NOTE: theres is a slight different behaviour because for example in 
        //winforms if your only had an item that started with A and press A the selectionIndex
        //will not change but a SelectedIndexChanged event (equivalent to SelectionChanged in Silverlight)
        //and this is not the Silverlight behaviour
    }
    
}

ASP to ASP.Net Migration: Fixing Includes

24. January 2011 08:43 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

During a migration from ASP to ASP.NET one of the biggest hurdles is finding a way to deal with the include files.

ASP was a interpreted environment whether ASP.NET is compiled and this difference is very important because you need to find ways more natural in .NET to do some things you used to do in ASP.

For example in ASP you used to have a set of common functionality that was included in your files. What will you do with that?

For ASP ASP.NET in VB.NET is a lot easier. One of the things you can do is move all those common subs and functions to a Module.

Now if what you have is a ASP.NET Web Site, then just your new modules to the App_Code folder and voila your pages are now able to see that code.

For a ASP.NET Web Application is just a little differente. What you have to do is move your common variables, constants, subs and functions to a Module, but that is not enough to make that code reachable from your mark up, so you have two alternatives:

1. Add an %@import Namespace=”QualfiedNamespaces.Module1”  statement for each of your modules.

2. Modify your web.config file and add under system.web something like:

<system.web>
              <pages>
                     <namespaces>
                           <add namespace="WebApplication1.Module1"/>
                     </namespaces>
                     
              </pages>

That will add an implicit import for all your pages.

For C# it can be a little more complicated. Because you do not have modules like in VB.NET, what you can do is use extension methods, to have a similiar syntax.

Split Config files in several files

6. January 2011 10:25 by Mrojas in General  //  Tags: , ,   //   Comments (0)

In .NET Framework 2.0 the attribute configSource was added to several elements of the .NET config files so you could use external files.

Sadly those attribute are not available for the system.serviceModel.However I found this post that shows a interesting workaround.

You can modify your serviceModel file to look like this:

<configuration>
 
  <system.serviceModel>
    <services configSource="Services.config" >
    </services>
 
    <bindings configSource="Bindings.config">
    </bindings>
 
    <behaviors configSource="Behaviors.config">
    </behaviors>
 
  </system.serviceModel>
 
</configuration>

And then you can put your configuration settings in separate files like the following:

Behaviors.config

<configuration>
 
  <system.serviceModel>
    <services configSource="Services.config" >
    </services>
 
    <bindings configSource="Bindings.config">
    </bindings>
 
    <behaviors configSource="Behaviors.config">
    </behaviors>
 
  </system.serviceModel>
 
</configuration>

For more details see the full post by Pablo Cibraro

Upgrading Applications Written in Earlier versions of Visual Basic for example VB4, VB5

21. December 2010 05:01 by Mrojas in   //  Tags: , , , , , , , , , ,   //   Comments (0)

Some time ago Artinsoft participated in the development of a book called “Upgrading Visual Basic 6.0 Applications”.

I quote from that book:

“The upgrade wizard is designed to upgrade Visual Basic 6.0 applications. For
projects written in Visual Basic versions 1.0 through 5.0, it is necessary that you first
upgrade them to Visual Basic 6.0 before upgrading to Visual Basic .NET. To upgrade
a project that was developed in a version earlier than Visual Basic 6.0, simply open
the project in the Visual Basic 6.0 IDE and save it. If Visual Basic 6.0 prompts you to
upgrade controls to Visual Basic 6.0, choose Yes. If the project contains Visual Basic
5.0 ActiveX controls, it is often best to replace these controls with Visual Basic 6.0
versions. This is because these controls use a different threading model than models
used by Visual Basic 6.0 controls. The earlier threading model is not supported in
Windows Forms.
For 16-bit projects written in Visual Basic versions 1.0 through 4.0, you may need to
make extra modifications to the application to convert it to Visual Basic 6.0.
VBX controls will not be automatically converted. You will also have to replace
Win16 Windows APIs with their Win32® counterparts.
Visual Basic versions 2.0 and 3.0 often require an extra step. Visual Basic 6.0 can only
open files in text format, whereas Visual Basic versions 2.0 and 3.0 support two file
formats: binary and text. Before upgrading these projects, ensure the entire applica-
tion is saved in text format by using the following procedure.

To convert Visual Basic 1.0 and 2.0 files to text format
1. On the File menu, click Save As.
2. In the Save dialog box, select the Save As Text check box.
Because Visual Basic 1.0 can only save files in binary format, all of these projects will
first need to be opened in Visual Basic 2.0 or 3.0 and then saved as text before they
can be converted to Visual Basic 6.0. After converting the project to Visual Basic 6.0,
you can begin the process of upgrading it to Visual Basic .NET.”

This book is available for free
from the MSDN

Could not load file or assembly ‘App_Web_ ….

16. December 2010 04:53 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

If you ever get an error like, it is an annoying situation where the web server is trying to use and old compilation of your aspx files.

The workaround I have is: rename web.config to stopweb.config.

Browse to the offending page URL it will return an error. After you receive the error rename stopweb.config to web.config

Browse to the offending page. This will force the server to compile the web pages.

And if it work the problem will now go away.

Migrate JSP to ASP.NET MVC

14. December 2010 06:19 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

ASP.NET has gone a long way. And it might be the right time to start moving your sites to ASP.NET.

But what happens if you have a big investment in JSP. Will I lose all my JSP skills?

Well ASP.NET is not the same as JSP but the MVC view engine concept can help you retain some of the JSP flavor.

A good MVC View Engine project is SharpTiles this project provides a partial implementation of JSTL and Tiles.

Just take a look at the the SharpTiles. Just as they say SharpTiles if for you if “You are a Java Developer and you don’t like .aspx”

Determine is executable is a console application

30. November 2010 03:36 by Mrojas in General  //  Tags: , ,   //   Comments (0)

 

I you were looking for a way to do that just take a look at this post: http://weblogs.asp.net/whaggard/archive/2004/08/30/223020.aspx

Just notice that for this post you need to add this struct:

[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
  public IntPtr hIcon;
  public IntPtr iIcon;
  public uint dwAttributes;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  public string szDisplayName;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  public string szTypeName;
};

Custom tool warning: Cannot import wsdl:portType

25. November 2010 05:04 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

During a Silverlight migration project from VB6 I was trying to add a WCF reference,
everything seemed to work in the wizard but no code was generated.

After reviewing the Warning messages, i found that some said:

Custom tool warning: Cannot import wsdl:portType

What I did to solve this issue?

1. Right click on your service reference

2. Select Configure Service reference

3. Uncheck the option that says Reuse types in referenced assemblies.

image

4. Press OK

After that VS generated the code and I could use the WCF service.

Lightswitch Experiences: Migrating Access to Microsoft Lightswitch

25. November 2010 03:07 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

 

 

Microsoft Access was (and is still) very used for simple data entry applications.
But Microsoft Access despite all its good is kind of an old technology and there was
no clear alternative for a simple mortal development environment… until Microsoft Lightswitch.

This series of posts illustrates the experiences of migrating Microsoft Access applications to LigthSwitch.

This post shows the result of migrating all Northwind Access example tables:

The following is Microsoft LightSwitch Solution explorer showing all Tables

image

 

And these are some of the Northwind tables in LIghtswitch

 

image

image

 

image

image

 

image

 

image

 

The migration process is straightforward. Text and Memo fields can be migrated to string, Numbers can be migrated to Int32 or Int64, Currency is map to Money. Yes\No can be mapped to boolean with a Value List.

There is support for specifying a caption (Display ID in Lightswitch), Description, and validation rules.

I will keep posting about Query migration, form migration and also  report migration. Stay tuned.

Categories