Its common to come across the below error when adding WCF service reference,
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: List of referenced types contains more than one type with data contract name '
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.
This happens because ServiceUtil is by default re uses all referenced assemblies in the project. And if any of the referenced assembly is not serializable or unable to reference then it will throw the above error.
To avoid this we can follow one of the below approaches,
Approach 1
Make sure that when using a service reference of a web service to a web application/any application , you follow below steps,
- After adding the service reference OR while adding the service reference , In Service Reference Settings Dialogue , check the Data Type section,
To Go to Service Reference Settings Dialog, Right click the service , Select "Configure Service Reference"
That will open the Service Reference Settings Dialog,
In this, Make sure that you have selected the option "Reuse types in referenced assemblies" -> "Reuse types in specified referenced assemblies".
By Default it will be "Reuse types in all referenced assemblies". It will look for all references you have added in the project, this is what causing error.
Approach 2
Another approach is to uncheck "Reuse types in all referenced assemblies" but when you are un checking this option, you may get compilation error as you might have references some dll's in Project. So before doing this you
Should be extra careful.