Thursday, May 7, 2009

Unable to download following files from asmx?wsdl

Problem:
Got another issue today. When a developer using VS.Net in another part of our organization calls our webservice the user gets a fun:

Unable to download following files from .
http://urlofwebservice/TestVD/WebService.asmx?wsdl
Do you want to skip these files and continue?
Yes No

Reproduction
:
The developer who is trying to resolve this issue needs access to another webserver.

  1. RDP into the webserver that is your test environment

  2. Copy the code (asmx, bin, config, wsdl, xsds, etc) in http://urlofwebservice/TestVD/ to a new directory called TestVD2.

  3. Create a new virtual directory called TestVD2 pointing to the new directory

  4. Now from your local machine in your vs.net project add a web reference to the http://urlOfWebservice/TestVDTest/WebService.asmx

  5. You'll get the error as stated above now. For some reason it can't resolve the wsdl.


Research:
First I did a search on how the WebService.asmx?wsdl page is created as it is not something we can see at design time. Found a blurb that said that this page is created using reflection at runtime based off the WebService.asmx page.

Resolution:

To resolve this issue:

  1. Open up the Webservice.asmx.cs page

  2. Change the WebServiceBinding at the top from:

  3. [WebServiceBinding("WebService1", "http://someurl/WSDL/WebService/v1_0_1", "http://localhost/TestVD/WebService.wsdl")]
    to
    [WebServiceBinding("WebService1", "http://someurl/WSDL/WebService/v1_0_1", "http://urlofwebservice/TestVD/WebService.wsdl")]
    Kinda weird here as the test we'll do later will be to TestVDTest which will have code that points to the wsdl on TestVD.
  4. Recompile

  5. Publish to a directory

  6. Copy new bin and asmx page out to test server in both the TestVD and TestVDTest.

  7. Follow steps in the reproduction section above to verify it picks up the wsdl and xsd's if you have'em.


Voila! You should be good now. The reflection of the asmx page picks up the localhost entry. Then when other developers out there don't have the locahost/TestVD directory the wsdl doesn't resolve. Change the localhost url to a url that others can resolve to and that fixes the problem.