Search code examples
c#asp.netweb-serviceswsdl

.net web service reference update while publishing


I have a web site project in which I use a web service to get data. The service is an .asmx within the same project as the website. Therefor the reference for this web service (endpoint in web.config, .svcinfo, .disco, .wsdl, and .svcmap) points to localhost while development. When deploying the web site (publish) I need the references to be updated before building so that it points to where I'm deploying it.

I have used web.config-transformations in different build contexts to update the references in web.config and tried to create a BeforeBuild task to generate .wsdl, .svcinfo, etc by calling SvcUtil.exe.

Web.config transformations work fine but SvcUtil.exe tries to discover the web service on the deployed address to generate the files so... as all this occurs while deploying then no files are generated due to there is no web service in the target address yet.

I figured out that the flow should be something like:
1- get target address from web.config-transformations
2- discover the LOCAL (within the project, not in the target) web service
3- create or update .wsdl, .disco, etc with target address
4- build
5- deploy

But I'm out of ideas on how to make it work... any ideas?


Solution

  • I am not sure if this applies to ASMX but in WCF it is enough to modify web.config using config transformations. No need to update service reference again. Update service reference only when there are changes in service methods.

    Generated service classes should use relative addresses. Address prefix is then red from web.config file.