Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType"

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?

like image 589
stiank81 Avatar asked Dec 09 '09 10:12

stiank81


2 Answers

I found my answer here: http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html

Long story short: I unchecked Reuse types in reference assemblies from the Advanced menu.


I don't know if this matters but i'm not using MVC, but Web Forms.

like image 109
Dragos Durlut Avatar answered Oct 12 '22 19:10

Dragos Durlut


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 control of the client and the service, we use the method described in this screencast.

like image 41
Shiraz Bhaiji Avatar answered Oct 12 '22 18:10

Shiraz Bhaiji