views:

300

answers:

3

Hi,

I have inherited a web site project that makes use of a number of WCF Web Services hosted on a BizTalk server. We have two environments that I need to deploy this project to, with different URLs for the different BizTalk servers.

i.e. In the Staging environment, I need to point the services at xx.xx.xx.101
In the Live environment, I need to point them at xx.xx.xx.102, or whatever.

Currently, we've got all of the URLs stored in keys in the web.config file, so that we can change them dynamically... Unfortunately this isn't working!

If I change the URL in the web.config to something other than what the project was compiled with, I get an error when calling the service:
Server did not recognize the value of HTTP Header SOAPAction: xx.xx.xx.101\ServiceName\MethodName

I'm told that the only way they've known to deploy this is to update the web.config URLs, change all of the web references in Visual Studio to match, click on "update web reference" for each reference in Visual Studio, and then compile.

It's driving me mad! I've written a pre-build NAnt script to go through and replace all instances of the URL found anywhere in the project directory, and even that isn't making any difference.

There must be something else being pulled down from the service when I click the "update reference", but I'm new to working with web services, and so I'm not sure what.

Does anyone have any ideas? Is there a way to do this programatically?

Thanks.

+2  A: 

Are the referenced webservices exactly the same on the different servers except for the Url? Especially the namespace must be the same for all the referenced services.

If the namespaces and everything else is exactly the same at your referenced webservice you will only have to update your webservice endpoint, not the whole web reference. You can set the endpoint by simly setting the Url property of your service to your config value

YourServiceReference yourService = new YourServiceReference();
yourService.Url = "http://yourconfigendpoint";

EDIT: This is for old-style webservices, not shure about WCF but should be similar..?

mattanja
Hi Mattanja, Sorry if I didn't make this clear, but I am already setting the URL property to the web.config value. After this is done, I am getting the error shown above. The service connects to the correct server, but then errors out after that.
NeilD
Yes, sorry I also noticed afterwards that I may not really have given you the answer you've been looking for :) - edited
mattanja
To be honest, I'm not convinced that the web services ARE the same on both servers. Unfortunately they aren't my servers, and it's difficult to check!
NeilD
OK then you could use something like SoapUI http://www.soapui.org/ to check.
mattanja
A: 

Hi, NeilD! I think that full replacement of URL in project is not the best solution. I think that calls to WCF Service in Web project made throw message contracts. Can you place here the code snippet of calling some service method. You have to replace only URL that present in proxy constructor. Other URLS, that specifies method name must stay immutable

Yuriy Khan
Hi Yuriy... The code to call the service method is almost identical to the snippet posted above by mattanja. I've managed to solve the problem using NAnt, but thanks for your time.
NeilD
A: 

Right... I think I've fixed it!

I've ditched all of the Visual Studio Web References, in favour of proxy classes generated by the NAntContrib "wsdl" task.

The script will now update all of the references depending on what type of build you have selected (Debug, Release, etc).

This still doesn't answer why the issue was happening in the first place, but I suspect it's as mattanja suggested, and there is some difference in the Web Services on each server.

Update The root cause of this problem was that whoever deployed the web services on the two servers had used different namespaces for each deployment. Redeploying the web services using the same namespace has solved the issue, and removed the need for all this NAnt silliness.

NeilD