views:

1892

answers:

2

I created a WCF service library project in my solution, and have service references to this. I use the services from a class library, so I have references from my WPF application project in addition to the class library. Services are set up straight forward - only changed to get async service functions.

Everything was working fine - until I wanted to update my service references. It failed, so I eventually rolled back and retried, but it failed even then! So - updating the service references fails without doing any changes to it. Why?!

The error I get is this one:

Custom tool error: Failed to generate code for the service reference 
'MyServiceReference'.  Please check other error and warning messages for details.

The warning gives more information:

Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: 
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Patient' in  
namespace 'http://schemas.datacontract.org/2004/07/MyApp.Model'. Need to exclude all but one of the 
following types. Only matching types can be valid references: 
"MyApp.Dashboard.MyServiceReference.Patient, Medski.Dashboard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
"MyApp.Model.Patient, MyApp.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']

There are two similar warnings too saying:

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='ISomeService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_ISomeService']

And the same for:

Custom tool warning: Cannot import wsdl:port ..

I find this all confusing.. I don't have a Patient class on the client side Dashboard except the one I got through the service reference. So what does it mean? And why does it suddenly show? Remember: I didn't even change anything!

Now, the solution to this was found here, but without an explanation to what this means. So; in the "Configure service reference" for the service I uncheck the "Reuse types in the referenced assemblies" checkbox. Rebuilding now it all works fine without problems. But what did I really change? Will this make an impact on my application? And when should one uncheck this? I do want to reuse the types I've set up DataContract on, but no more. Will I still get access to those without this checked?

+3  A: 

When you add a service reference, there are two ways the types that are used by the service can be handled:

  • The types are stored in a dll, and that dll is referenced from both the client and the server application.
  • The types are not in a dll referenced by the client. In that case the tool that creates the service reference, will create the types in the references.cs file.

There are many things that can go wrong. We have found that if the tool crashes, it is sometimes faster to delete the service reference and start again.

We have stopped using service reference. For projects where we have controll of the client and the service, we use the method described in this screencast.

Shiraz Bhaiji
Thanks! I actually found that screencast yesterday. Watched it, and it was truelly an eye opener! Am planning to move to that structure once I get the basics in place. Sounds like you've been struggeling with some of the same problems I'm seeing. I too often end up deleting and readding the service references when something oddly goes wrong, and that's not a good sign.. Hoping the described architecture will help!
stiank81
+2  A: 

Go to Advanced properties while adding reference and remove "System.Window.Browser" from the checklist, It solves the problem.

Sridhar Subramanian
Thx! Not using Service References anymore - doing the manual approach described in the screencast from the answer by @Shiraz. But this is nice to know anyway!
stiank81