Server Did Not Recognise The Value Of HTTP Header SOAPAction (Or How Not To Add A New WebMethod to an existing WebService)

December 17, 2009 by baraholka1

This can come about when your Web Services References file (automatically generated by Visual Studio) is out of sync with your asmx file because you have manually hacked added some Web Methods. Make sure that all your WebMethods have corresponding entries in the Web Service Web Reference file (Reference.vb or Reference.cs).

WARNING: If you are trying to Add a new WebMethod to an existing Web Service do not do what I did below. It will only consign you to a Journey of Pain.

I am maintaining an app. that has a large WebService that operates on a group of DataSets. Each DataSet has three WebMethods associated with it. I created a new DataSet, cut and pasted the three standard Web Methods the app. needs to operate on the new DataSet and manually hacked the Reference.vb file to set up the calls to Invoke the Web Method and the Async versions of the Web Method i.e this stuff:

Public Function GetPreviewSEODataSetByDomain(ByVal domaincode As Integer) As System.Data.DataSet
Dim results() As Object = Me.Invoke(“GetPreviewSEODataSetByDomain”, New Object() {domaincode})
Return CType(results(0), System.Data.DataSet)
End Function

BUT I only manually hacked in the necessary Invokes for ONE of the WebMethods, not all three. For some reason this caused the SOAPAction error. When I removed the other two WebMethods from the asmx file the error went away.

If the above does not pertain to you, make sure you haven’t messed up the Web Service Namespace.

Now here’s what I should have done:

How To Add A New WebMethod to an existing WebService

1. Add the new Web Method to your asmx file. Decorate with WebMethod attribute of course.
2. Get Visual Studio to update the WebReference file, Reference.vb/Reeference.cs. This file does not belong to the Web Service per se. Rather it belongs to the Project which calls the WebService. Visual Studio generates it when you add the Web Reference.

To update it, locate the reference to your Web Service in your calling Project’s Web Reference folder, right-click and select Update Web Reference from the Context Menu. No more hacking, everything works, pain in cranium stops. To celebrate, I recommend making yourself a free instant coffee from the staff room. That’s what I did. (NB. This is unconnected to actually debugging your WebService)

Cannot Drag Additional Table From Server Explorer Into Existing DataSet (.xsd) Failed to add TableAdapter.

December 8, 2009 by baraholka1

Just a short one here,…

I have a very complicated DataSet (.xsd) file and our schema is being updated. I needed to drag a couple of new tables from the ServerExplorer into the DataSet Designer…but Visual Studio wouldn’t let me do it. I just got the ‘ghostbusters’ icon and the table would not drop.

Trying to work around the issue, I did right-click on Designer Add->TableAdapter and configured the Adapter but when clicking ‘Finish’ I got the error ‘Failed to add TableAdapter’ along with the SQL Named Pipes Provider error 40.

For half an hour I toyed with hand-coding the necessary table and all associated ADO.NET code directly into the DataSet designer file. Fortunately this madness subsided.

Then I created a new DataSet and copied/pasted the old DataSet from the Designer into the new one. This worked. No Named Pipes errors AND I was able to drag new tables into the Designer for the new DataSet. But this was all just a Journey Of Pain. I should be able to simply edit the existing DataSet. I threw a brick through the monitor and went home for a relaxing session of concreting the hamster (also here) to let my right-brain work on the problem unencumbered by reason.

Well today’s a new day and since it was my last straw, what I did was rebind the Project to Visual Source Safe. I had unbound the Project from Soure Control a little earlier for weird reasons I will keep to myself. Once I rebound the Project to Source Control via File -> Source Control -> Change Source Control I was able to add the new table to the Dataset. This was so stupidly illogical that it did not surprise me in the least.

Once day I will be able to explain why this makes any difference but today I can’t. But if you’re in a similar position why not try rebinding the Source Control? It worked for me and now I’m a multi-millionaire with a full head of hair and a tremendously loyal pet Aardvark. Buy one today.

WPF: Replicating MDI Application Behaviour

November 25, 2009 by baraholka1

I decided to use Prism, aka Microsoft Composite Application Guidance For WPF and Silverlight.

This is very much like using a supersonic jet fighter to pop down to the local shops but its effective, not very hard and does not require you to write reams of fragile custom code. You just need to spend a bit of time getting used to Prism. Now that’s not a trivial task, but you should have covered the fundamental concepts within a working week, assuming you have some prior knowledge of Dependency Injection.

The huge advantage to you is that Prism is written by people who are much better programmers than you or I are, so the code is robust, whereas writing a custom MDI Window Manager is out of the league of most Intermediate-level developers (most of us).

Very simply, Prism allows the development of Modular Applications in which the User Interface of an application is decomposed into loosely-coupled Modules, each of which occupies a specific area on the screen, known as a Region.

No window (known in Prism as a View) can move outside the Region in which it is contained. This replicates the MDI-like behaviour you’re looking for.

Prism is also a library of Best Practices – it’s produced by the Microsoft Patterns and Practices team – so you get heaps of built-ins for free. And there’s a helpful forum where others using Prism are happy to help us newbies.

You can also have multiple windows (views) open simultaneously if you want, but this will render as a tabbed interface which is not exactly the same as MDI.

I embarked upon this approach and have been successful in producing a MDI-like app. It wasn’t too hard and I learnt heaps along the way. Go for it.

Visual Studio 2008 Disappears From Screen When Loading Solution or Project

November 5, 2009 by baraholka1

I started up Visual Studio 2008 and clicked on my Solution file AmazingSolution on the Start Page. Visual Studio started dragging up the solution and was just loading up a XAML file when it disappeared. Just disappeared.

This was about as expected as a nasty case of Sponteneous Combustion. Alice In Wonderland is one of my favourite books but when Visual Studio starts behaving like the Chesire Cat it’s a little perturbing…more so since I had just hacked the Registry to overcome the issue of Intellisense not appearing in XAML files after installation of Windows SDK.

My terror was complete. I had destroyed Visual Studio.

The paramedics were called, the Emergency Sacrifical Ferret put on stand-by and I ran a repair on Visual Studio, as Microsoft Connect recommended.

Then I rebooted, restarted Visual Studio and loaded AmazingProject. Visual Studio disappeared again. I slaughtered the Ferret and ordered a crate of Vodka in celebration of my impending sacking, but then checked the Event Logs. Glory! It contained a very useful entry:

.NET Runtime version 2.0.50727.3603 – Fatal Execution Engine Error (7A036050) (80131506)

and Googling that showed that Microsoft Connect have patch files for that very issue…Well, it was too late for the Ferret, but I HADN”T DESTROYED VISUAL STUDIO AFTER ALL!

To Summarize

1. The horrifying sudden disappearance of Visual Studio 2008 can be caused by a bug relating to the loading of XAML files. Check your Event Logs and if you see .NET Runtime version 2.0.50727.3603 – Fatal Execution Engine Error get the patch from Microsoft Connect at the link above. No Ferrets need to be slaughtered.

2. The unrelated problem of Intellisense disappearing from XAML files is caused by installing a Windows SDK after (on top of) Visual Studio 2008. This overwrites the registry key VS uses to locate the XAML Intellisense file. To fix that, run a Repair on Visual Studio 2008 or, if you’re feeling brave, hack the registry.

So What Happened To You ?

Sick of having no Intellisense in XAML I Googled the registry hack. At the same time I did a ‘Close All But Me’ in Visual Studio on a XAML file then closed Visual Studio. I then restarted Visual Studio to allow the registry hack to take effect, whereupon it did the Chesire Cat on me. It was simply a malevolent coincidence…perhaps a warning never to do a registry hack when a more polite known fix exists :-) (In this case the Visual Studio Repair.

Hey Bruce, chuck us another Ferret will ya ?

WPF Setting Default Sort Order For Datagrid Without Using A Static Resource

November 4, 2009 by baraholka1

For this you need a CollectionViewSource and bind the DataGrid ItemsSource to the View property of the CollectionViewSource.

The Basic Wire-Up
Andrea Boschin on Silverlight PlayGround demonstrates the basic wiring for Binding the DataGrid ItemsSource to the CollectionViewSource. Andrea is using MVVM and hence the CollectionViewSource is a property in his ViewModel class. I’ve excerpted it here:

Public Class SomeViewModel

// The View of this cvs will get bound to a datagrid
Public CollectionViewSource People { get; set; }

// The actual data that the cvs will construct its view out of
protected ObservableCollection(Of People) PeopleInternal { get; set; }
}
} //end class

In XAML, bind the DataGrid to the View of the People CollectionViewSource:

wpftoolkit:DataGrid ItemsSource="{Binding People.View}"
wpftoolkit:DataGrid.Columns
wpftoolkit:DataGridTextColumn Header="Name"
MinWidth="120" Binding="{Binding Path=Name, Mode=TwoWay}" /
wpftoolkit:DataGridTextColumn Header="Age"
Width="auto" Binding="{Binding Path=Age, Mode=TwoWay}" /
/dg:DataGrid.Columns
/wpftoolkit:DataGrid

Taking over from where Andrea left off, when the ObservableCollection is set, we initialise the CollectionViewSource:


protected ObservableCollection(Of People) PeopleInternal
{ get {return _peopleInternal };
set;
{
_peopleInternal = value
People.Source = _peopleInternal
}
}

Setting Default Sort Order
In order to establish the default Sort Order for the Datagrid, add a SortDescription to the CollectionViewSource that the DataGrid is bound to. This creates the required view.

Let’s say we wanted our Datagrid to have a sort order of ‘Name’, assuming ‘Name’ is a field on the People class.


protected ObservableCollection(Of People) PeopleInternal
{ get {return _peopleInternal };
set;
{
_peopleInternal = value
People.Source = _peopleInternal
// Setting Sort Order for People
// Sort by Name field
People.SortDescriptions.Clear()
SortDescription sd = new SortDescription("Name", ListSortOrder.Ascending)
People.SortDescriptions.Add(sd)
}
}

So, every time PeopleInternal is updated, the CollectionViewSource creates a view on PeopleInternal which is sorted by Name. This is held in People.View. Because the DataGrid is bound to this View the data in it is always sorted by name when the ItemsSource (the ObservableCollection(Of People) is initialised

This works around the behaviour in the WPF Toolkit DataGrid where all SortDescriptions for the DataGrid are lost when the ItemsSource is initialised

Of course, users will still be able to click on Column Headers and sort at any time on any other column they want to.

Over-Complexifying WPF Applications using Prism

October 27, 2009 by baraholka1

For those getting started in WPF I recommend the WPF Boot Camp 2008 videos. Make sure you clink on the extended list of links.

An unexpected highlight was Glenn Block of Microsoft Patterns and Practices talking about Prism, the Composite Application Block for WPF. While valiantly attempting to explain Prism to a beginner audience in WPF without assuming prior knowledge of Dependency Injection, Glenn tells us:

There are things we can do to avoid over-complexifying an application beyond its natural complexity

I had trouble understanding this so I used Babelfish to Refactor it into Portuguese, from there into French, from there into German, from there into Greek and than back into English:

It exists things that we can make avoid a sobre-complexifying application apart from their natural complexity

That was a little better, but for added clarity I performed a second-phase refactoring, repeating the previous steps:

It exists the things that a application sobre-complexifying omitted their natural complexity you avoid this they can it can

If you have any further questions, please ping the Microsoft Patterns and Practices Team.

VB.NET ‘Type or Namespace cannot be found.’ after converting VS 2005 projects into VS 2008

October 23, 2009 by baraholka1

I am converting some VB.NET projects from VS 2005 into VS 2008. I had converted the projects ‘Animals’ and ‘Food’, put them into a Solution, Zoo.sln, added a Project Reference for Food into the Animals project and compiled the Solution which duly compiled and ran.

Visual Studio 2008 Conversion Report Ambiguous
But, examining the Conversion Report for ‘Food’, I noticed that only the Food.vbproj file was marked as converted. The summary at the end of the log said:

Converted: 1 file.
Not Converted: 72 files.

This made me worried. Why were there 72 files Not Converted ? Had I actually converted Food properly ? Angst got the better of me, so I Unloaded and Removed Food from Zoo.sln, retrieved the source again from Visual Source Safe and reconverted the Project.

I got the same result: 1 file converted (just the vbproj) and 72 files with no status next to them (but no errors either) and a count of 72 ‘Not Converted’.

I Googled here and there and eventually found a forum post by the knowledgable Peter Bromberg which said that Class files (.vb and .cs) will not by touched by the VS 2005 to VS 2008 Conversion. That put me at ease. So then I re-added Food to Zoo.sln, added the Project Reference into Animals as before and recompiled.

This time 102 errors: Horrific memories of school examinations covered in red pen filled my mind.

All the errors said the same thing: ‘Type or Namespace xyz cannot be found. (Are you missing an Imports or Assembly Reference) ?‘ All the errors were in ‘Anmals’ referring to unknown types which I knew existed in ‘Food’.

Well, I checked the Project Properties for ‘Animals’ and the Reference to Food ws there and it was to the correct Food.dll. I removed the reference, recompiled Food and re-added the Reference. Still 102 errors. Things hadn’t looked this grim since the days I flunked MacroEconomics 2A with a score so low it had to be examined through a microscope.

Prodding The Corpse

Here was a typical line returning two unknown type errors on MonkeyDrink:
Dim fermentedCoconut As MonkeyDrink = New MonkeyDrink()

As an experiment I tried the following:
Dim fermentedCoconut As Food.MonkeyDrink = New Food.MonkeyDrink()

To my amazement, Food.MonkeyDrink appeared in Intellisense and resolved to a known type, reducing my error count. So Animals obviously had a valid Reference to Food. Why then the compile error ?

Now you’re probably thinking ‘the dolt has left out his Import statements in the class files’ but remember these projects were converted – they never had Imports statements in them in the first place, yet Animals had always compiled with Food before. WHY was it chucking a spaz now ? The pain, the pain, the journey of pain…

Unknown Feature #999

Checking again the References Tab in the Property Page for the Animals Project, I clicked on Food in the References list then scrolled further down and noticed for the first time a pick list of namespaces from all the Referenced projects: Lo and Behold, Food was not selected. Once I selected Food (thus telling the compiler to Import all the Namespaces from Food) and recompiled, my errors vanished with the silken ease of Master Ninjas after a successful assassination.

The miraculous feature I had discovered is the Visual Studio Imported Namespaces List which MSDN beautifully describes here

The Imported Namespaces List is only available in VB Projects (not C#), that’s why I had never seen it before.

So Now I Know

If your Types cannot be found in your VB.NET project but you know the containing project is referenced, or maybe you’re wondering why your Class files have absolutely NO Imports statements in them, have a look at the Imported Namespaces List in the Project Designer via Project Properties. It’s….how you say…verrrrry nice.

WPF MVVM in VB.NET: Delegating Event Subscriptions for RoutedCommand (or any ICommand) in the ViewModel

October 21, 2009 by baraholka1

Just started a new project in WPF. It’s my first WPF project and the firm’s first WPF project. Should be lots to blog about.

Stick One In His Eye

We are using MVVM because the WPF Pantheon (e.g. John Grossman, Josh Smith and Jason Dolinger) are in agreement that this pattern is eminently suited to WPF. So, yeah, we’re taking a bit of a Voodoo Architecture approach.

I am writing a Proof Of Concept using MVVM and found an absolutely brilliant video by Jason Dolinger here which shows a comprehensive refactoring example in MVVM while lucidly explaining the pattern. I was following the vid while coding my Proof Of Concept but got well and truly stuck on the part where Jason delegates (that’s del-e-GATEs as a verb) event subscriptions for the RoutedCommand in the ViewModel.

The Google To End All Googles

The reason I got stuck was that the vid is in C# whereas I am using VB.NET, which is not a problem in itself, but Jason was using C# Event Accessors to delegate the Event subscription. I had never heard of Event Accessors, Jason did not say what they were and VB.NET does not have them (at least not by that name).

I commenced a Google and soon saw that all the MSDN WPF examples are in C# only and not in VB.NET. I was looking for something I didn’t know the name of to do something I didn’t understand in a language which did not have the construct I needed. I was just about to wave a Dead Chicken at the monitor when, in the end Google did cough up an answer…in French. Impossible n’est pas français.

Here’s what had me stuck. What I needed was the VB.NET translation for this code

public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}

First I had to figure out what the heck it was doing. Jason just said ‘now we have to wire the ICommand into the WPF Commanding system’ which left me very little the wiser. Well, ladies and gentlemen what you are witnessing above is the use of an Event Accessor to delegate (That’s del-e-GATE as a verb, not DEL-e-gate as a noun) event subscriptions.

In more detail, the ‘add’ Event Accessor is fired when an Event Subscription to CanExecuteChanged occurs. Value contains the Delegate i.e. Event Handler which is subscribing to the Event. Hence, the Event Handler denoted by value is being added to the Event Handler List for the CommandManager RequerySuggested event. This has the effect of wiring the WPF ICommand object that has that event subscription into the WPF Commanding infrastructure, thus allowing that ICommand to take effect.

VB.NET does not have Event Accessors but it does have a direct equivalent, namely Custom Events. Here’s the equivalent VB.NET code:


Public Custom Event CanExecuteChanged As EventHandler Implements System.Windows.Input.ICommand.CanExecuteChanged
AddHandler(ByVal value As EventHandler)
'This is the AddHandler block
AddHandler CommandManager.RequerySuggested, value
End AddHandler

RemoveHandler(ByVal value As EventHandler)
'This is the RemoveHandler block
RemoveHandler CommandManager.RequerySuggested, value
End RemoveHandler
'
RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
'This is the RaiseEvent block
CommandManager.InvalidateRequerySuggested()
End RaiseEvent
End Event

You can see its the same thing as a set of C# Event Accessors.

For the above code I am sobbing in helpless gratitude to binoo, moderateur of the WPF Forum at Devellopez.Com who posted the above code in this thread, entitled Modèle MVVM – Implémentation ICommand

What Are Custom Events ?

Mesdames and messuirs, you may read about Custom Events here. They enable custom handling of AddHandler, RemoveHandler and RaiseEvent calls for any event.

The above code, for example says that when AddHandler is called for a CanExecuteChanged event that the event handler for that event should be added to the RequerySuggested event of the CommandManager. The inverse happens for RemoveHandler and CommandManager.InvalidateRequerySuggested() is called when a RaiseEvent is done on a CanExecuteChanged event.

Further Reading

I will assume that anyone interested in this post knows about MVVM in WPF and why I would be wanting to wire up ICommand objects in the ViewModel, but for those who have heroically read this far without that pre-requisite knowledge, just click on the MVVM link at the start of the article and the one about the MVVM refactoring video.

And to binoo, now my favourite moderateur in the world, may your hovercraft be ever full of eels and your Brie only Triple Cream.

BTWT Semi-Officially ‘Somewhat Funny’

October 14, 2009 by baraholka1

Checking referrers to my blog I found that rumbergd in this Yahoo Groups Discussion had found a post I had done on LINQ Context.SubmitChanges to be useful and ’somewhat funny’, which are my two primary aims for Bite The Wax Tadpole.

But then again, maybe rumbergd was describing the article that I linked to and not the article that I actually wrote. Surely not…blurb…

If anyone interested also interesting post:

http://waxtadpole.wordpress.com/2008/05/08/linq-contextsubmitchanges-does-not-ad\

d-record-to-database/

And the link from it:

http://www.codinghorror.com/blog/archives/001079.html

Main idea – ‘always assume the problem is in your code’ :) ))
I found that article pretty interesting and somewhat funny.

DataBinding WinForms CheckedListBox

October 12, 2009 by baraholka1

Noting some confusion in the Greater Google on the subject of the CheckedListBox, I want to make it clear that this article is about the WINFORMS CheckedListBox class (System.Windows.Forms.CheckedListBox), NOT the WebForms CheckBoxList class (System.Web.UI.WebControls.CheckBoxList). So back to your Postbacks all you WebForms freaks.

Generating CheckedListBox Text
The CheckedListBox is a ListBox which includes a CheckBox to the left of the display text. The display text is computed using the ToString method of the object in the Items collection of the CheckedListBox.

It is also possible, however, to generate the text in each CheckedListBox entry by associating the CheckedListBox with a DataSource and setting the DisplayMember field of the CheckedListBox.

Microsoft do not encourage the use of CheckedListBox DataSource. None of the DataSource, DisplayMember or ValueMember members of CheckedListBox appear in the Intellisense for the control or in the Designer Properties Window because Microsoft has added the Browsable=false attribute to these properties. In the MSDN example, programmers are referred directly to the Items collection as the means of wiring up the control:

To add objects to the list at run time, assign an array of object references with the AddRange method. The list then displays the default string value for each object. You can add individual items to the list with the Add method.

Microsoft MSDN advises users not to use the DataSource member of CheckedListBox because this control is not intended to be DataBound and unpredictable results can ensue if you use the control in a DataBound way. However the DataSource, ValueMember and DisplayMember members can be used as I discovered from Moz2 in this MSDN social forum thread

Why Would You Bother ?
It’s a fair question. For me, I needed to produce a Windows Form with identical look and feel to an existing form which utilised a CheckedListBox, but for processing efficiency also required a SelectedValue member. That led me into a fruitful Googling session which I am now sharing with you.

Setting CheckedListBox DataSource
You can set the DataSource to any Collection. But you must set DataSource after DisplayMember is set. Here’s some VB.NET for your reading pleasure:


'Event Handler for WebSiteType dropdown selected index changed
'Update Listed Domains in CheckBox List clbWebDomain based on selected WebSiteType
Private Sub cboWebSiteType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboWebSiteType.SelectedIndexChanged
Me.clbWebDomain.DataSource = Nothing
Me.clbWebDomain.Items.Clear()
...Update Me.WebDomainMappingList...
Me.clbWebDomain.ValueMember = "DomainCode"
Me.clbWebDomain.DisplayMember = "URL"
Me.clbWebDomain.DataSource = Me.WebDomainMappingList
...Code to initialise clbWebDomain.Items.....
End Sub

WebDomainMappingList is a GenericList of my Custom Class WebDomainMapping.

Since that WebDomainMapping Class is only used for temporary processing, I actually implemented it as a Structure. I didn’t put in a ToString implementation as I wanted it clear via the DisplayMember that I wanted to display the URL property…and that leads me to my next point, the DisplayMember and ValueMember members must refer to Properties of the Objects/Structures in the Items collection of your CheckedListBox. They cannot be mere fields otherwise your CheckedListBox will fill up with garbage.

Therefore, the following will NOT work:

Friend Structure WebDomainMapping
Dim URL As String
Dim DomainCode As Integer
End Structure

Putting an Object/Structure like this into the Items collection of a CheckedListBox and then using the URL property as a DisplayMember will cause the following output to your CheckedListBox for all the entries. This is actually the default ToString() representation of the object in your CheckedListBox Items Collection

Namespace.frmReport+WebDomainMapping
Namespace.frmReport+WebDomainMapping
etc.

An Object/Structure definition like this will work. It wlll allow URL to be used as the DisplayMember of the CheckedListBox.

Friend Structure WebDomainMapping
Private _URL As String
Public Property URL() As String
Get
Return _URL
End Get
Set (ByVal value As String)
_URL = value
End Set
End Property

Private _DomainCode As Integer
...Property Declaration for DomainCode....
End Structure

Directly Initialise The Items Collection Too
It is not enough merely to initialise the DataSource member of CheckedListBox. You must also directly initialise the Items Collection if you don’t do this you will not get anything at all displayed in the CheckedListBox.

Naturally, the Items collection must contain EXACTLY the same Objects as the DataSource.

Remember, true DataBinding as represented by DataSource, DisplayMember and ValueMember is not officially supported for this control, so utilising these members may not provide the functionality you would expect or may not work at all. For example, here the Items Collection is not automatically populated by assigning the DataSource. What you can do, as I have done, is patch together an implementation or approximation of DataBinding for CheckedListBox. The functionality, or at least most of it, is there because it is inherited from Base Controls.

Final Caveats
The partial implementation of DataBinding in CheckedListBox and hence its flaky functionality is recognised by Microsoft as a bug (see preceeding links), but there is no guarantee this will be fixed to support full DataBinding. Microsoft may decide to chop DataSource from CheckedListBox entirely. I used the above workaround in version 2.0 of the Framework. Who knows, it might be gone or not work at all in later versions.

Why DataBinding Can Only Be To Properties and not Fields
Nikhail Koltari who is a Software Architect at Microsoft, explains some of the reasons why here.