Blog from Saravanan Arumugam

Let us talk about Technologies

Category Archives: Silverlight

Unrecognized element ‘wsDualHttpBinding’ in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.


This is an extension to my previous post ServiceReference.ClientConfig is not populated with Service Reference

When I created a proxy and config file by using SvcUtil.exe, I had to copy the app.config content into ServiceReference.ClientConfig.

Note: Instead of creating app.config and copying it into ServiceReference.ClientConfig, I could have used /config:ServiceReference.ClientConfig switch directly in the SvcUtil.

The build was successful but while accessing the service, I got the following runtime exception.

Exception:

Unrecognized element ‘wsDualHttpBinding’ in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.

 

Solution:

The solution was simple. Change the binding to basicHttpBinding, pollingDuplexHttpBinding or customBinding.

Advertisements

ServiceReference.ClientConfig is not populated with Service Reference


Exception:

I came across a strange behavior of Visual Studio. When I made a Service reference in my Silverlight application, the visual studio created the classes and schemas; but not the config file (ServiceReference.ClientConfig)

 

Solution:

The reasons for having ServiceReference.ClientConfig not populated could be many. But in my case, I was using wsDualHttpBinding in the service (a duplex channeled service).

wsDualHttpBinding and may other bindings are not supported by Silverlight. To be precise Silverlight supports only BasicHttpBinding, pollingDuplexHttpBinding (supported with Silverlight 4) and customBinding.

When I made some changes in the service and changed the binding as basicHttpBinding, the Service Reference update populated the ServiceReference.ClientConfig file.

It could have been better if the service reference threw exception saying that the Silverlight supports only a subset of WCF bindings, instead of completing the reference successfully leaving the Config file incomplete. Hopefully the future releases of Visual studio would do that.

 

The following forum helped me narrow the issue.

Failed to generate the service reference WCF service

The given key was not present in the dictionary


I was getting the following exception in the WCF proxy initialization statement. This happened in my Silverlight client application.

Exception:

The given key was not present in the dictionary

Later I realized that I created app.config file using SvcUtil.exe.

Silverlight uses ServiceReference.ClientConfig in places of app.cofig/web.config.

 

Solution:

When I copied the app.config content into ServiceReference.ClientConfig, I got rid of the issue.

 

Note: Looks like the error “The given key was not present in the dictionary” will be thrown to say that no endpoint is specified.

Reference: Getting tired of "The given key was not present in the dictionary"

Generate asynchronous operations is checked and disabled in Service Reference Dialog


I have observed that from a sliver light client, Visual studio doesn’t allow creation of Synchronous WCF services.

When I tried to use the service reference dialog from a Silver light client, I was shown the following

image

Here we can see Generate asynchronous operations is grayed out and always checked.

This appeared to be that Visual Studio always recommends the use of Asynchronous operations.

I further tried by creating the synchronous operations through SvcUtil.exe

C:\Users\Saravanan\Projects>svcutil http://localhost:54927/GreetingService.svc?
wsdl /out:GreetingServiceProxy.cs /l:cs /config:app.config

 

But the runtime threw the following exception.

The contract ‘IGreetingService’ contains synchronous operations, which are not supported in Silverlight. Split the operations into "Begin" and "End" parts and set the AsyncPattern property on the OperationContractAttribute to ‘true’. Note that you do not have to make the same change on the server.

 

So it is evident that Silverlight supports only asynchronous web service calls.

Refer to How to: Access a Service from Silverlight and Why does my service reference only generate asynchronous methods? for more detail.