none
Failed to generate code for the service reference

    Question

  • I have a solution with several projects, more than one of which call my WebService and they work.  I added a new project to the solution, put some fields and a button on the screen.  I recompile the solution, and there are no errors.  When I try to add  service reference to my WebService, I get the error below.  Remove the Service reference and no errors.  I also copied the clientConfig from one of the other projects over since the one being genereated is basically empty.  And I copied a version to my base .Web project.   I still get the errror. 

    Next, I added a new project, copied over all the code...it worked!   For a few minutes.  But now Im getting the same error again.

    Currently, if I delete the clientConfig, and do an update service reference, the file only contains

          <configuration />

    And as stated, copying over a good clientConfig does not resolve the problem.

    Error 7 Custom tool error: Failed to generate code for the service reference 'myWebSvc'.  Please check other error and warning messages for details. D:\!SilverLight\IsildoSilverlight\Members\Service References\myWebSvc\Reference.svcmap 1 1 Members

    Sunday, December 14, 2008 11:28 PM

Answers

  • Well,, no responses.   I have finally gotten a solution thats doesnt have this error.  So, If your having this problem do this

    • 1: Go thru all your projectes and delete all the clientConfigs, webService References, and the Service References Directories.
    • 2: In one method or another delete the existing Web Service and Create a new one with all your subs and functions copied over.
    • 3. DO NOT name it the same thing, so somethng like myWebSvc_03_ for the 3d time you have done this process.  Fortunately, on this interation, all seems well. I can even do an update WebService without destroying the links.  Makes me wonder how much junk is hanging out in the code somewhere.  I dont know if this is true or not, but it seemed to have worked best when I created all the projects and then added the sebService last. I do know that I had problems when adding a new project to the solution after the web service was working.
    • 4. Rebuild, and then go add you service references back into your solutions and update the code as needed.

    Maybe I should just make the webservice a totally separate entity, but I am the ony one that would use it, so that seemed a additional complication. 

    One sort of unrelated note... You may have a solution that has a user control called in it, but itself is not using the web service.  My project requires that I copy a clientConfig from another project.  And then if you do a rebuild of the web service, you my have to update this as well.

    Im rather new to Silverlight, but this has been a real pain and a lot of work time lost due to this issue.

    So, not an answer, but perhaps a workaround that will save you some of the pain that I have encountered.

    Im marking this as answered, although its not really.  At best its a workaround.

    Sunday, December 21, 2008 10:15 AM

All replies

  • D:\!SilverLight\IsildoSilverlight\Members\Service References\myWebSvc\Reference.svcmap <
    Monday, December 15, 2008 6:34 PM
  • I now have 2 projects with this problem in this solution.  The project compiles and runs if I dont try to reference the WebService in the code.(with the above error message).

    I dont know if this helps any, but in the affected projects, I looked at the files in my Web Service.  I see the usual files, I see Reference.Svcmap with a sub of Reference.vb but the two .datasource files are not being generated. 

    The two projects deal with login and member data, so Im not going to get much futher unless I can reference the WebService.

    Update ***  Ok, I totally reconstructed the project.  Before copying over the code, I created all my Web references,etc. Once that was working, I copied over all the 10 projects code, resources,classes. etc. 

    It worked.  That is until I needed to make a change to the WebService. I had to add a space to the end of a Select statement line.  I recompiled the WebService, did an Update Service Reference ...BOOM.  No  .datasource files in some of the projects

    On possible clue. All the user controls that are being called into another project are OK.  Top level projects all are failing.  So,,, Next I guess Im going to create a dummy project that does nothing but call the next projects. 

    ReConstructing the projects every time just isnt working for me!

     

    Tuesday, December 16, 2008 11:07 AM
  • Well,, no responses.   I have finally gotten a solution thats doesnt have this error.  So, If your having this problem do this

    • 1: Go thru all your projectes and delete all the clientConfigs, webService References, and the Service References Directories.
    • 2: In one method or another delete the existing Web Service and Create a new one with all your subs and functions copied over.
    • 3. DO NOT name it the same thing, so somethng like myWebSvc_03_ for the 3d time you have done this process.  Fortunately, on this interation, all seems well. I can even do an update WebService without destroying the links.  Makes me wonder how much junk is hanging out in the code somewhere.  I dont know if this is true or not, but it seemed to have worked best when I created all the projects and then added the sebService last. I do know that I had problems when adding a new project to the solution after the web service was working.
    • 4. Rebuild, and then go add you service references back into your solutions and update the code as needed.

    Maybe I should just make the webservice a totally separate entity, but I am the ony one that would use it, so that seemed a additional complication. 

    One sort of unrelated note... You may have a solution that has a user control called in it, but itself is not using the web service.  My project requires that I copy a clientConfig from another project.  And then if you do a rebuild of the web service, you my have to update this as well.

    Im rather new to Silverlight, but this has been a real pain and a lot of work time lost due to this issue.

    So, not an answer, but perhaps a workaround that will save you some of the pain that I have encountered.

    Im marking this as answered, although its not really.  At best its a workaround.

    Sunday, December 21, 2008 10:15 AM
  • Check this,

    http://software-development-toolbox.blogspot.com/2009/02/creating-service-reference-failed-to.html

    It really fixed the problem for me

    • Proposed as answer by Brian Cook Thursday, September 04, 2014 1:12 PM
    • Unproposed as answer by Brian Cook Thursday, September 04, 2014 1:12 PM
    • Proposed as answer by Brian Cook Thursday, September 04, 2014 1:13 PM
    Wednesday, July 01, 2009 4:22 AM
  • I'm having a similar problem. It was working then stop all of a sudden.  I thought I'd post in hopes of helping someone else figure out their problem.

    You can find what is causing the error following these steps. This utility also shows you all the activity that is taking place with your WCF service.

    http://msdn.microsoft.com/en-us/library/ms732023.aspx
    1. Setup the web.config (or app.config) of the project the service is located in to save the trace
    <system.diagnostics>
        <trace autoflush="true" />
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
            <listeners>
              <add name="sdt"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData="wcfTrace2.svclog" />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>
    a. initializeData can be a path.
    2. Download the svcviewer
    3. Setup the external tool in VS.
    a. C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\SvcTraceViewer.exe
    4. View the log to find problems and see what WCF is doing

    Wednesday, July 15, 2009 10:57 AM
  • re: "silverlight Failed to generate code for the service reference" 

    I do something similar to ScCrow but it might be slightly easier. 

    1. Delete the service

    2. Add it back with a new name that you never used before

    3. Build (you will get errors for your reference)
       Check (e.g. with Intellisense) that the reference to the service exists

    4. Delete the service

    5. Add it back with the original name

    6. It should work :)

     

    Thursday, July 30, 2009 9:57 PM
  • Here is another solution: I have had this exact same issue before. In the Properties for the project ensure that you do not have dot-seperated assembly names, in other words an assembly named MyProjects.MyAssemby because this can cause the issue. I was able to resole the issue by removing this the dot (so MyProjects.MyAssemby ==> MyProjectsMyAssembly) and then simply executed the "Update Service Reference". The Reference.cs file, which had been empty on previous attempts, was correctly populated and the service worked as it should have. Hope this helps others who run into this issue
    Tuesday, November 03, 2009 7:48 PM
  • i'm using silverlight 4 and this issue is still happening.

    i didn't even change the webservice. i just rebuilt it and updated the service reference in my silverlight. now reference.vb is empty, clientconfig is empty.

    i tried removing the service reference and re-add it. but the files are still empty.

     

    Friday, October 15, 2010 6:29 AM
  • I have been unable to solve this in VS2010 Ultimate by any of the aforementioned methods.  I instead generated the service reference in VS2010 Express for Windows Phone and copied the reference.cs file over to its own class to my project.

    Tuesday, November 09, 2010 11:07 AM
  • Could you please elaborate.  Why on Earth would that solve the problem.  Why would having dot's in your namespace cause a problem?  Why would it work the first couple of times, but the last time, not work?  All of this is consfusing and frustrating to me.

    Sunday, August 14, 2011 11:07 AM
  • I had this problem in a Windows Phone Silverlight project. To get around it I had to navigate to the Solution in the File Explorer and find the ServiceReference folder in my client and delete all of it's contents. I then readded the service and it worked. 

    Sunday, October 09, 2011 9:26 PM
  • re: "silverlight Failed to generate code for the service reference" 

    I do something similar to ScCrow but it might be slightly easier. 

    1. Delete the service

    2. Add it back with a new name that you never used before

    3. Build (you will get errors for your reference)
       Check (e.g. with Intellisense) that the reference to the service exists

    4. Delete the service

    5. Add it back with the original name

    6. It should work :)

     

    Monica's solution worked for me, FWIW.  Thank you, Monica!

    Thursday, October 27, 2011 1:13 PM
  • Hey, I also had a problem with a webservice. Turned out, and I must admit this to be more luck than wisdom, that the Collection Type was System.Collection.ObjectModel.ObservableCollection by default. When I changed this to System.Array, I had no problems anymore.

    Monday, January 02, 2012 6:21 AM
  • I had the same problem, none of the methods could solve it, so I tried something else and worked out just fine. When you create the service reference all you need to do is to go to "Advanced" and there you need to uncheck the Reuse types in all referenced assemblies from Configure service reference option.

     

    That should do it... Good luck

    Wednesday, May 16, 2012 11:36 AM
  • For those who are still having this problem, I found a little quirk with VS and wp7 solutions.

    you can read more about the VS bug here:

    https://connect.microsoft.com/VisualStudio/feedback/details/624984/error-warnings-when-adding-web-reference-on-windows-phone-7-project

    I found that by running Visual Studio WITHOUT Admin privileges, deleting the service reference, deleting the clientconfig, then readding the reference (Kept the same reference name), it all worked again.  I'm not sure if it applies to Silverlight WP7 solutions only, but it's worth a shot.

    Thursday, July 26, 2012 1:18 AM