views:

1332

answers:

1

I'm using Silverlight 3 Prism (CAB) with WCF

When I call a WCF service in a Prism module, I get the same error:

"Could not find default endpoint element that references contract 'IMyService' in the service model client configuaration section. This might be because no configuaration file was found for your application or because no end point element matching this contract could be found in the client element"

It turns out that its looking in the Shell's .xap file for a ServiceReferences.ClientConfig file, not in the module's ServiceReferences.ClientConfig file. I added my endpoint and binding to the existing ServiceReferences.ClientConfig file in my Silverlight Shell application (it calls it's own WCF services).

Then I had to rebuild the Shell app to generate the new .xap file for my Web project's ClientBin folder.

Next I changed to setting up the service in code:

// create the binding elements
BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement();
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement() 
{ MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue};

HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement() 
{ MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };

// add the binding elements into a Custom Binding
CustomBinding customBinding;
if (Application.Current.Host.Source.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase))
{
    customBinding = new CustomBinding(binaryMessageEncoding, httpsTransport);
}
else
{
    customBinding = new CustomBinding(binaryMessageEncoding, httpTransport);
}

// create the Endpoint URL
EndpointAddress endpointAddress = new EndpointAddress(

"http://localhost/Test/TestModule/Test.TestModule.WCF/TestModuleService.svc");

// create an interface for the WCF service
var service = new TestModuleServiceClient(customBinding, endpointAddress);