Hilton Giesenow's Jumbled Mind

Tuesday, August 03, 2004

Web Service Exception in Visual Studio 2003

I've been working quite a bit with XML Web Services lately, and every now and then I get the following exception:

"Only one WebServiceBinding attribute may be specified on type..."

A search on Google returned few results, only one of which was helpful. It suggested restarting Visual Studio. This works, but I was curious as to what was happening. I discovered that Visual Studio.Net stores a cached version of whatever Web Application is currently open, and that this cache can become corrupted. The location of this cache can be found in Tools - Options - Projects - Web Settings, under the "Offline Projects" section. To fix this problem, browse to the folder and delete the specific cache for the web services project, then close and re-open the solution from within V.S. Alternatively, as the gotdotnet posting suggests, just close and re-open the entire IDE. I've also heard of other problems occurring from this cache becoming corrupted, but there does not seem to be an actual way to rebuild it directly from within Visual Studio.

Does anybody know of a way to do this?


  • Now i know why it happens :)
    Easier fix: Select "Rebuild Solution" from the Build menu.

    By Anonymous Morgan, at 3:31 PM  

  • In some cases, you have to right click on the service in "web references", and select "update web reference" before doing "rebuild solution"

    By Anonymous Anonymous, at 2:20 PM  

  • The previous commment about updating the web references "as well" - this is the sure-fire way to fix this problem, although it doesn't help with the fact that it shows up in the first place. There's no need to manually clear the cache nor unload and reload the IDE if you update the web references. Usually it's quicker, especially if you have a large project.

    As to why it happens - as I'm sure you've all seen, the error actually occurs when the webservice class NEW method is executing. There's a little piece of code that reads:

    If (Not (urlSetting) Is Nothing) Then
    Me.Url = String.Concat(urlSetting, "")
    Me.Url = "http://blah.blah.com/blah/blah.asmx"
    End If

    The error is thrown when executing the String.Concat command. It strikes me as peculiar that, given that it is explcitly "illegal" to assign more than one WebServiceBinding attribute, why should the VSDesigner source code generator auto-generate something that does exactly that?

    I just comment out the if, concat, else and endif and leave the explicit URL assignment and the problem goes away. The good news is that it never seems to happen in production - only when running the app from the IDE.

    By Anonymous Steve Marron, at 11:47 PM  

  • The solutions listed above don't solve the problem for me.

    Here's what I do:
    - Update every Web Reference in every project in my solution (4 projects, 4 references)
    - Rebuild Solution
    - Run Solution

    Still get the same error. Any other ideas?

    One other comment - I reference the same webservice from 2 different projects, and I didn't notice this error showing up before I did this - could this have anything to do with it?

    By Anonymous Anonymous, at 12:14 AM  

  • Hi,

    The solution listed above does not work for me - here's what I do:

    - Update all the web references in all the projects in my solution (4 projects, 4 web references, 2 actual web services)

    - Rebuild Solution

    - "Start" solution

    I still get the same error unless I close down the IDE and bring it back up.

    One other thing to note: I didn't start getting this error until I had two projects in my Solution that referenced the same WebService... could this have anything to do with it?

    By Anonymous Anonymous, at 12:16 AM  

  • Sorry for the double (now triple, I guess) post.

    By Anonymous Anonymous, at 12:17 AM  

  • Hi,

    I was just spooked by this on a test server that does not have Visual Studio installed. I found out that we had 2 web references to the same web service in 2 different projects in the solution so I have deleted one of them.

    I sure hope this works, though it is hard to say as the site has run fine for days before the error showed its ugly face.

    By Anonymous Michael Harmsen, at 11:58 AM  

Post a Comment

<< Home