Prism - Adding Service References

Topics: Prism v4 - WPF 4
Jul 28, 2013 at 9:27 PM
Is there a recommended way to hook up a prism application to a WCF service? I've tried adding a service reference to my project (it has Prism.UnityExtensions installed via nuget), but whenever I try to update the service references, it throws an error stating that it didn't update.

On investigating the warnings associated with it, it appears like it's unable to import the wsdl:porttype because it's looking for unity v2.1.505.
Jul 29, 2013 at 4:35 PM
Edited Jul 29, 2013 at 4:35 PM
Hi,

As far as I know, there's no official guidance regarding WCF services in Prism, since Prism is client-side oriented. However, I believe there are examples of how to consume a WCF service from a Prism application. For example, the following blog post by Guido Maliandi portrays such scenario:

Although the sample is implemented in Silverlight I believe you might find it useful in order to apply the same concepts in a WPF application.

Regarding your error message, it would be helpful if you can provide the full error message you are receiving and which version of Unity you are using in your application.

Regards,

Federico Martinez
http://blogs.southworks.net/fmartinez
Jul 29, 2013 at 9:12 PM
Edited Jul 29, 2013 at 9:17 PM
Thanks Federico. That link looks to be a winner - I'm not trying to use prism on the WCF side (I'll handle that separately), just consume it from a Prism client.

Edit: Scratch that, they aren't really doing anything different per se. I haven't set up settings in the shell app.config yet, but these issues are at design time.

In terms of the error(s), I've install prism.unityextensions via nuget (and let it install prism and unity as necessary), then ran an update-package on the solution to bring everything up to the current version on nuget. When I attempt to perform an "Update Service Reference" on the reference, I get the below warnings (sorry for the dump):
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService1'] D:\User Folders\MyUser\Documents\Visual Studio 2013\Projects\PrismWithServiceTest\PrismWithServiceTest\Service References\ServiceReference1\Reference.svcmap 1 1 PrismWithServiceTest
Warning 2 Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService1'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IService1'] D:\User Folders\MyUser\Documents\Visual Studio 2013\Projects\PrismWithServiceTest\PrismWithServiceTest\Service References\ServiceReference1\Reference.svcmap 1 1 PrismWithServiceTest
Warning 3 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IService1'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='Service1']/wsdl:port[@name='BasicHttpBinding_IService1'] D:\User Folders\MyUser\Documents\Visual Studio 2013\Projects\PrismWithServiceTest\PrismWithServiceTest\Service References\ServiceReference1\Reference.svcmap 1 1 PrismWithServiceTest
Warning 4 Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService1'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.microsoft.com/ws/2005/02/mex/bindings']/wsdl:binding[@name='MetadataExchangeHttpBinding_IService1'] D:\User Folders\MyUser\Documents\Visual Studio 2013\Projects\PrismWithServiceTest\PrismWithServiceTest\Service References\ServiceReference1\Reference.svcmap 1 1 PrismWithServiceTest
Warning 5 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://schemas.microsoft.com/ws/2005/02/mex/bindings']/wsdl:binding[@name='MetadataExchangeHttpBinding_IService1'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='Service1']/wsdl:port[@name='MetadataExchangeHttpBinding_IService1'] D:\User Folders\MyUser\Documents\Visual Studio 2013\Projects\PrismWithServiceTest\PrismWithServiceTest\Service References\ServiceReference1\Reference.svcmap 1 1 PrismWithServiceTest
Error 6 Custom tool error: Failed to generate code for the service reference 'ServiceReference1'. Please check other error and warning messages for details. D:\User Folders\MyUser\Documents\Visual Studio 2013\Projects\PrismWithServiceTest\PrismWithServiceTest\Service References\ServiceReference1\Reference.svcmap 1 1 PrismWithServiceTest
Jul 30, 2013 at 6:23 PM
Hi,

It seems that your WCF service is asking for Microsoft.Practices.ServiceLocation, which is somehow strange since ServiceLocation is related to Prism and not WCF. If your service is referencing ServiceLocation, try removing that reference to see if it solves your problem. If it doesn't, you could also delete the reference to your service from the Prism side and then reference it again. It is possible that some leftover files from previous builds could be conflicting with newer builds of your service.

If these steps fail to solve your problem, it would be useful if you can provide us with a repro sample of your application or the scenario you are trying to achieve, so that we can analyze it in further detail.

Regards,

Federico Martinez
http://blogs.southworks.net/fmartinez
Jul 30, 2013 at 7:51 PM
Hi Federico,

Yeah it's strange, as the WCF service has no references to prism whatsoever.

You can find the solution here. I've not been getting it to work in my app, so been trying with this simple app, to strip out the possibility of it being my code that was the issue.

When you open it, you can see the warnings/error straight away.

Thanks
Fergal
Jul 31, 2013 at 5:06 PM
Hi,

I tested the sample you provided on Visual Studio 2012 and it seems to be working fine. No error or warning messages were shown after opening the sample, and even after a clean build. Therefore, I believe that the root of your problem relies on your local configuration. I noticed that you seem to be using Visual Studio 2013, which is still in Preview, so it should be probably related to the errors and warnings you are receiving.

Regards,

Federico Martinez
http://blogs.southworks.net/fmartinez
Jul 31, 2013 at 5:21 PM
Yep, you are right. I hadn't even noticed I was using the 2013 preview - must have moved my icons around.

Cheers for the help.