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=’http://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 (12)

  1. Jude Okello says:

    Thanks , that was a lifesaver!

  2. Farhan Ahmad says:

    That worked.  Thanks!

  3. LSergio says:

    That worked.  Thanks!

  4. franck says:

    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

  5. Valon says:

    Thank you so much … God bless you …

  6. Praburaj Thiagarajan says:

    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.

  7. Bruno F says:

    Thanks you so much !

  8. Praburaj Thiagarajan says:

    These are the KB articles :

    Win8 / Win2012 : support.microsoft.com/…/2750149

    Downlevel OS : support.microsoft.com/…/2750147

  9. Amruta says:

    Thanks. That worked for me. 🙂

  10. Thanga Prakash says:

    Thanks a ton..