8/21/2008

Silverlight 2 Beta 2: ConfigUnrecognizedElement issue and Fix

 

When you create a Service Reference in a Silverlight App to an ASMX WebService, you may get the: 

"An unhanded exception ('Sys.InvalidOperationException: ManagedRuntimeError error #4004 in control 'Xaml1': System.InvalidOperationException: ConfigUnrecognizedElement at System.ServiceModel.Configuration.BindingsSection.ReadXml(XmlReader reader)"

Exception. This "is a real bug".  When your Visual Studio 2008 Silverlight app generates the ServiceReferences.ClientConfig file, it creates a customBinding section that it cannot parse. In fact even the IDE marks the customBinding tag with squiggles saying "The element 'bindings' has invalid child element 'customBinding'. List of possible elements expected: 'basicHttpBinding'."

This is because SIlverlight doesn't understand SOAP 1.2, which is the default for ASMX webservices. DUH! To fix, you can do this with WCF:

<customBinding>
<binding name="myBinding">
<textMessageEncoding messageVersion="Soap11"/>
<httpTransport/>
</binding>
</customBinding>

Or, with ASMX, you can do this:

<webServices >
<protocols>
<remove name="HttpSoap12"/>
</protocols>
</webServices>

 

Those of course would be in your server-side web.config file.

The problem here is that the tools are creating a custom binding that is unnecessary and improper. If Silverlight can't support SOAP 1.2  then the tools should not be creating this binding. Silverlight should also ignore any bindings it doesn't know about.

WCF is great, but for simple deployment and auto-documentation in the service discovery page, I still prefer ASMX.

 

FACTOID:  Count Basie would be 100 years old today. The guy made a huge contribution to American Jazz, and dozens of jazz greats came out of his band. Here’s a clip of his band doing Neil Hefti’s “Lil Darlin’”:

BTW - it was Neil Hefti who wrote the original Batman theme.