.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > Failed to generate code for the service reference
Ask a questionAsk a question
 

AnswerFailed to generate code for the service reference

  • Wednesday, June 11, 2008 5:16 AMRajeshaz09 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I am using two WCF services in my website. Both are using same class as data contract. At the time of compiling i am getting the error...

     

    Code Snippet

    Error 1 Reference.svcmap: Failed to generate code for the service reference 'CustomerServiceReference'.  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 'DropDownDataBase' in namespace 'http://schemas.datacontract.org/2004/07/WcfServiceLibrary.DataContracts'. Need to exclude all but one of the following types. Only matching types can be valid references:   "VoyagerApplication.CRM.CustomerServiceReference.DropDownDataBase, CRM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)  "VoyagerApplication.CRM.AEServiceReference.DropDownDataBase, CRM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)  "VoyagerApplication.Customers.CustomerServiceReference.DropDownDataBase, Customers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)  XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ICustomerService']  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='ICustomerService']  XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_ICustomerService']  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='WSHttpBinding_ICustomerService']  XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='CustomerService']/wsdl:port[@name='WSHttpBinding_ICustomerService'] App_WebReferences/CustomerServiceReference/

     

     

     


     

    Developing WCF services is not my hand. I need only access those services for my web site. 

     

    Can any one tell me to resolve this conflict?

     

    Thanks

Answers

  • Wednesday, June 11, 2008 8:02 AMLars WilhelmsenMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Rajeshaz09,

     

     I would recommend that you use the same data contracts in both the service and client as you describe - but have you duplicated the code, or do you use the /r switch (for svcutil.exe) or in the Advanced... dialog of the Add Service Reference dialog - have you enabled reusing types from all assemblies?

     

     You should put your data contracts in an assembly separate both from your service and your client - and add a reference to it from both.

     

    Good luck,

     

     --larsw

     

  • Thursday, June 12, 2008 12:41 AMLifeng Lu - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    It looks like the 'CustomerServiceReference' has been defined in two assemblies referenced by your project.  The code generator has no idea about which one should be used.

     

    To get rid of this problem, just like Lars said.  You can configure your service reference, in its advance options tab, you can disable "reuse types in all referenced assemblies", (by select "reuse types in specified referenced assemblies").  You can select all assemblies except the assembly causing this problem (which defines the CustomerServiceReference as the error message said.)

     

    Another solution is to change the assembly containing the CustomerServiceReference.  What you want to do is to reconfigure its service reference to "Internal/Friend' in the advanced options.  By default, 'public' classes are generated, and if you import a same reference twice or in two class library projects, the conflict might happen ifwhen you consume it later.

     

     

All Replies

  • Wednesday, June 11, 2008 8:02 AMLars WilhelmsenMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Rajeshaz09,

     

     I would recommend that you use the same data contracts in both the service and client as you describe - but have you duplicated the code, or do you use the /r switch (for svcutil.exe) or in the Advanced... dialog of the Add Service Reference dialog - have you enabled reusing types from all assemblies?

     

     You should put your data contracts in an assembly separate both from your service and your client - and add a reference to it from both.

     

    Good luck,

     

     --larsw

     

  • Thursday, June 12, 2008 12:41 AMLifeng Lu - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    It looks like the 'CustomerServiceReference' has been defined in two assemblies referenced by your project.  The code generator has no idea about which one should be used.

     

    To get rid of this problem, just like Lars said.  You can configure your service reference, in its advance options tab, you can disable "reuse types in all referenced assemblies", (by select "reuse types in specified referenced assemblies").  You can select all assemblies except the assembly causing this problem (which defines the CustomerServiceReference as the error message said.)

     

    Another solution is to change the assembly containing the CustomerServiceReference.  What you want to do is to reconfigure its service reference to "Internal/Friend' in the advanced options.  By default, 'public' classes are generated, and if you import a same reference twice or in two class library projects, the conflict might happen ifwhen you consume it later.

     

     

  • Thursday, June 12, 2008 5:15 AMRajeshaz09 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks Lars ...

     

    I used separate assembly concept as you said. It is working perfectly. One again thank you. 

     

  • Wednesday, October 21, 2009 11:09 AMTimmyC Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello!

    I am getting this error, but the above fix does not solve the issue, however I do know what has caused it.

    I have an edmx file in a WCF webservice which feeds a silverlight app.  The edmx is quite complex and a bit fragile, but was working fine up until I introduced our Industry Codes view into the model.  The view is basically { ID, ParentID, Name, ... }.  In my model I have created an association to itself which describes Children(*)/Parent(0/1) so I have a nice and tidy hierarchical structure.  The edmx and the service build without any errors - hurrah!  However, when I update the service reference I then get the below error (and a whole load of others as none of the webservice objects exist anymore):
    Error 21 Custom tool error: Failed to generate code for the service reference 'WCF_ContactAdmin'.  Please check other error and warning messages for details. X:\2008-054 ContactAdmin_Silverlight\Contact2_Admin_Silverlight\Service References\WCF_ContactAdmin\Reference.svcmap 1 1 Contact2_Admin_Silverlight
    When I try the fix mentioned in the link above this error disappears, but then so do all the objects in the datamodel, so I cannot continue from there.

    Having the hierarchical data objects defined in the EDM will make like so much easier in future, any help will be greatly appreciated, thank you!!

    Tim

    Web Developer at Terrapinn
  • Wednesday, October 21, 2009 11:22 AMTimmyC Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    And now it works.  I read somewhere else that if you close Visual Studio, re-open it, delete the webservice reference and re-add it it worked.  Well, true enough that worked for me.  Blimey what a fragile thing this is :-p

    Thanks anyway! :-)

    Tim
    Web Developer at Terrapinn
  • Thursday, November 05, 2009 12:24 PMphalluz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I had the same problem and tried the solution of TimmyC, which worked for me! thx!!
  • Saturday, November 07, 2009 5:12 PMNo no no Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    TimmyC's close VS2010 -> open VS2010-> delete service reference -> re-add service reference  dance worked for me too. I'm wondering if the development web server that VS2010 spins up is the culprit?

    Anyway, thanks to TimmyC and I agree, it's a bloody fragile thing this .NET 4.0 stack.  Sometimes I feel like breathing in the wrong direction is going to break references to something somewhere.