The ‘name’ configuration element key cannot be null

When you create a simple .Net 4 WCF Service Application it generates a simplified web.config file with default endpoints. This is great when you need a simple service and don’t want a cluttered config file. However, I did come across a small issue with the default file when you try to open it with the Service Configuration Editor. When you try to open the file an error is displayed; ‘The ‘name’ configuration element key cannot be null’. To fix the problem just add the name attribute to the behavior node;

<behaviors>
    <serviceBehaviors>
        <behavior name="defaultBehaviour">
            <serviceMetadata httpGetEnabled="true" />
        </behavior>
    </serviceBehaviors>
 </behaviors>
Advertisements

Making WCF RIA Services work in a DMZ/Multitier architecture using Application Request Routing

If your web services are running on a server that is not in the DMZ and you are not able to open port 80 to these services either then you will encounter a common scenario. Your Silverlight application will not be able to connect to these services because it can’t get to the clientaccesspolicy.xml file that is required to access services on a different server to the one that served your Silverlight application.

If you hosting your Silverlight application on a machine running IIS 7.5 (Windows Server 2008) then help is at hand – click here for more details.

Retrieving parameters passed to WCF Async method

This useful tip came in very handy for me…

Silverlight and Session variables

I have seen numerous postings about how to access Session data from the current HttpContext using WCF. A simple example can be found here. Whilst looking for a solution to another Silverlight problem I came across this post about passing large text to SL using initParams and it got me thinking. Could I use the same concept to read my Session variables?

The short answer is Yes, with a few small changes. My initial problem was that my session variable contained a class of complex types. In order to serialize this I just need to mark the class as [Serializable]. I then set my initParams value:

<param name="InitParams" value="<%=InitParams%>" />

In the code behind for the page hosting the SL control I added:

protected string InitParams { get; private set; }

Then I just needed to convert my Session variable to a Base64 string during the Page_Load event.

MemoryStream stream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
serializer.Serialize(stream, <my session variable> );       // Of type MyClass
stream.Position = 0;
string data = Convert.ToBase64String(stream.ToArray());
InitParams = "SessionDetails=" + data;

In my Silverlight Page, I just had to do the reverse to get my class back from the Base64 string.

if (App.Current.Host.InitParams.ContainsKey("SessionDetails"))
{
    MemoryStream ms = new MemoryStream(Convert.FromBase64String(App.Current.Host.InitParams["SessionDetails"]));
    StreamReader sr = new StreamReader(ms);
    string s = sr.ReadToEnd();

    sr.Close();
    sr.Dispose();

    ms.Close();
    ms.Dispose();

    // Parse the string so we can determine the contents of the Session variable
    XElement xElement = XElement.Parse(s);
}

And that is about it. The only other thing that is required is a bit a LINQ to get to the necessary values within the Session variable. Obviously this only works if you need to read in the Session variables one time when the SL control loads, but for me this was perfectly suitable.

The remote server returned an error: NotFound

Always start with the obvious…if you are using Silverlight make sure you have a basicHttpBinding endpoint specified for the WCF service. Otherwise, the request will not even make it to the server because the relevant endpoint is ‘NotFound‘.