Freigeben über


Add service reference adding empty reference.cs in MVC 4 projects of VS 2012

In VS 2012 MVC 4 projects, do you find an empty reference.cs file while adding a service reference to a WCF service using 'Add service reference' dialog?

Here is what you can do about it:

Check if your error tab shows some error like...

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: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself.

XPath to Error Source: //wsdl:definitions[@targetNamespace='https://tempuri.org/']/wsdl:portType[@name='IService1']

If so, you can use the following work around(s):

1. In add service reference dialog -> [Advanced ... ] -> Reuse types in referenced assemblies (Checked by default) -> Choose the non default 'Reuse types in specified referenced assemblies' radio -> Make sure you exclude Newtonsoft.Json.dll from the list. Try adding service reference now and see it succeeds.

2. Alternatively you can remove reference of this Newtonsoft.Json.dll while generating proxy and add that back after proxy generation is complete.

Comments

  • Anonymous
    August 23, 2012
    Thanks , that was a lifesaver!

  • Anonymous
    September 17, 2012
    That worked.  Thanks!

  • Anonymous
    October 02, 2012
    That worked.  Thanks!

  • Anonymous
    November 16, 2012
    Thanks!

  • Anonymous
    December 29, 2012
    I find it doesn't work that 'Reuse types in referenced assemblies' when add new  wcf service reference in MVC 4 projects it works well in Web application service client will generate used entities, and they are conflict with referenced assembiles can I have your ideas ? franck.gao@gmail.com

  • Anonymous
    June 11, 2013
    The comment has been removed

  • Anonymous
    June 11, 2013
    This issue should have been fixed with the latest updates for .net framework. Make sure you have all the updates installed from windows updates. Then you don't have to apply this work around.

  • Anonymous
    August 01, 2013
    Thanks you so much !

  • Anonymous
    August 16, 2013
    These are the KB articles : Win8 / Win2012 : support.microsoft.com/.../2750149 Downlevel OS : support.microsoft.com/.../2750147

  • Anonymous
    August 27, 2013
    Thanks. That worked for me. :)

  • Anonymous
    September 04, 2013
    Thanx.!!

  • Anonymous
    July 06, 2014
    Thanks a ton..