We all know that Silverlight application needs some service in order to communicate with the database. One of the ways is to use WCF service reference in your Silverlight application. When you add any WCF service reference in your application, it automatically adds the “ServiceReference.ClientConfig” file with the end point configuration having “BasicHttpBindings”, as till Silverlight version 4.0, works only with “BasicHttpBindings”. If the end points are not configured automatically, the user may get an error while communicating with the service. Below are the sample WCF service bindings in ServiceReference.ClientConfig file.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name=”BasicHttpBinding_IWCFService” maxBufferSize=”2147483647″
maxReceivedMessageSize=”2147483647″>
<security mode=”None”>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address=”http://URL of your WCF service Address”
binding=”basicHttpBinding” bindingConfiguration=” BasicHttpBinding_IWCFService ”
contract=”Your Service namespace.servicecontract”
name=”Your end point name” />
</client>
</system.serviceModel>
Most of the time it is needed that we have use secure HTTP i.e. https for the security of our application. In this case, the above bindings will not work. Your Silverlight application will fail to establish the connection with the WCF service. In order to work the same WCF service, we have to modify our end points as below and it will start working.
If you have deployed the application on IIS, you may need to wait for some time in order to reflect the changes, even if you have reset the IIS
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name=”BasicHttpBinding_IWCFService” maxBufferSize=”2147483647″
maxReceivedMessageSize=”2147483647″>
<security mode=”Transport”>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address=https://URL of your WCF service Address
binding=”basicHttpBinding” bindingConfiguration=” BasicHttpBinding_IWCFService ”
contract=”Your Service namespace.servicecontract”
name=”Your end point name” />
</client>
</system.serviceModel>