开发者

Update Web Reference in Visual Studio

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 开发者_如何学Pythonthen compile.

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 not sure what.

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


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..?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜