Design Time Support for Data in Blend and Visual Studio 2010

by Shawn January 13, 2010 10:36

Tags: , , , ,

Development

Generic Databinding with Silverlight

by Shawn June 01, 2009 10:22

This is one of those missing features that really makes you ask "what are they thinking" -- complex business systems that allow for on the fly customizations (something that is very common today) need to be able to be handled in Silverlight.

So if you are running into this and not sure how to proceed, here are some links that you might find useful

http://silverlight.net/forums/t/16733.aspx
http://silverlight.net/forums/t/63057.aspx
http://silverlight.net/forums/t/11570.aspx

http://silverlight.codeplex.com/WorkItem/View.aspx?WorkItemId=2810

Tags: ,

Development

Adding an entery to a List in SharePoint via code

by Shawn June 01, 2009 09:11

Check out this article on how to add a item to a list in SharePoint via code 

Tags: ,

SharePoint

How to Resolve WCF Issue: Can't host WCF service in a website with multiple identities

by Shawn April 28, 2009 12:18

When a WCF service is hosted in a IIS website which has multiple identities, that is, responds on different hostnames/ports, the WCF service, when created, throws the exception below:

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

I am aware that this behavior is by design and I believe that it can be resolved. I'm searching to forums, MSDN and blogs but no solution was found. I'm only found one solution to create a custom ServiceHostFactory which filters the additional base addresses and instantiates the service on one of them only. Thank to Zeddy for the helps. This issue can be resolved by creating a custom ServiceHostFactory which clear all baseAddresses then override Behaviors and ServiceEndPoint described below.

Create Custom ServiceHostFactory

Create new class for custom ServiceHostFactory below.

using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Linq;
using System.ServiceModel.Description;

public class MultipleIISBindingSupportServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        // return the emply list Uri to make it automatically select baseAddresses by endpoint configuration
        var host = base.CreateServiceHost(serviceType, new Uri[] {/*empty*/ });

        // Setup MEX dynamically
        var behavior = new ServiceMetadataBehavior
                           {
                               HttpGetEnabled = true,
                               HttpGetUrl = baseAddresses.Where(addr => addr.Scheme == "http").First()
                           };
        host.Description.Behaviors.Add(behavior);
        
        // Setup Endpoint configuration dynamically
        foreach (var uri in baseAddresses)
        {
            // Service endpoint support http scheme only, exclude https scheme
            if (uri.Scheme == "http")
            {
                host.AddServiceEndpoint(serviceType,
                                        new BasicHttpBinding(BasicHttpSecurityMode.None),
                                        uri
                    );
            }
        }
        return host;
    }
} 

Modify WCF Service Markup

To modify WCF Service Markup, right click on the MyService.svc file and then click "View Markup".

<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="MyService.svc.cs" Factory="MultipleIISBindingSupportServiceHostFactory" %>

Modify Web.config File

Open web.config file and going to line with <system.serviceModel> element, replace <system.serviceModel> and all child elements with following config.

<system.serviceModel>
	<diagnostics>
		<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
	</diagnostics>
	<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

After all steps above was done, the multiple identities issue should be resolved.

I hope this tips will be helpful.

Tags: ,

Development

Creating and Handling Faults in Silverlight

by Shawn April 28, 2009 10:52

Tags: , ,

Development

How to handle: An error occured creating the configuration section handler for system.serviceModel/behaviors…

by Shawn April 28, 2009 10:49

Are you developing an extension to Windows Communication Foundation (for example a behavior or message encoder) with configuration file support? If you are you may be getting frustraited by an exception something like the following (the precise nature depends on the kind of extension you are developing).

I was, and the frustraiting thing was that I had built some of these in the past for various purposes without any issues so I had a real tough time figuring out what the hell was going on. Well it turns out that it is a string comparison issue. Lets take a look at the configuration file for a WCF service:

In this configuration file I have a simple math service but I have applied an endpoint behavior to it called “beep” in the configuration file. This is a custom behavior so I’ve had to implement my own BehaviorExtensionElement and in this case I’ve implemented the element and the actual IEndpointBehavior in the same class (because I can). What happens is when WCF initialises it loads in the list of the extensions into a hashtable (simplication - there is a lot more code involved than just a hashtable-like data structure) - so in this case “beep” is mapped to “ServerApplication.BeepBehavior….”, at the same time an instance of the class specified in the second value is instansiated and stored.

As execution continues and the service host is brought online the <beep /> element is encounted. The aforementioned hashtable is looked up and the fully qualified class name is retreived. This is then used as a key to find the custom BehaviorExtensionElement and this is where it comes unstuck. When the BehaviorExtensionElement is stored it is indexed with the fully qualified type name which is fetched using .GetType(), when this value is rendered as a string it looks like this:

ServerApplication.BeepBehavior, ServerApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Notice the spaces between each of the type name elements. Now - compare this to the screenshot of the configuration file above. As you can see there is no space between the type name elements. Since the lookup is based on a simple string comparison the space is significant and the WCF runtime can’t find the previously created BehaviorExtensionElement instance and it all falls in a heap - if you go and put the spaces in it works perfectly.

The frustraiting thing is that the space sensitivity of the type attribute in the WCF portions of the configuration files is completely at odds with the norms in the rest of the .NET Framework (although I am aware of some similar issues in WPF thanks to Darren). Unfortunately it looks like Tomas Restrepo found the issue as well in this feedback entry on Microsoft Connect - but it looks like all development was closed off and it obviously shipped with this quirk.

Personally I think that this needs to be treated as a bug and fixed as soon as possible because it is going to drive developers who try to extend WCF completely nuts and when they realise what the problem was the WCF team better hope they are no where within reach. Given it isn’t a critical bug I suspect that it may have to wait for a service pack to be issued though.

Reprint from:
http://notgartner.wordpress.com/2006/12/19/rant-an-error-occured-creating-the-configuration-section-handler-for-systemservicemodelbehaviors/

Tags: ,

Development

Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies

by Shawn February 09, 2009 13:13

Rick Strahl recently wrote up a great blog article on Monitoring HTTP output for .NET HTTP Clients nad WCF Proxies.  I highly recommend that you check it out as soon as you can.

 Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies

Tags: ,

Development

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen | Modified by Mooglegiant