編輯 - 我也許應該提到我們使用需要綁定使用所產生的WCF樣式的Web服務SISvcUtil.exe
(這是WebServiceClient類的來源)。
我們在測試服務器和生產服務器上做了類似的事情,並且很容易更改Web服務指向的URL。很明顯,這確實假設託管在所有不同位置的Web服務是相同的......
當創建使用Web服務的Client對象時,您需要指定綁定和端點地址,您可以簡單地更改endpointaddress字符串指向適當的服務器。下面的代碼應該給你一個如何做到這一點的想法...
BasicHttpBinding binding = new BasicHttpBinding();
binding.OpenTimeout = new TimeSpan(0,1,0);
binding.CloseTimeout = new TimeSpan(0,1,0);
binding.SendTimeout = new TimeSpan(0,1,0);
//snip - any other bindings you need to specify...
string fullDomain;
string domain;
if (local)
domain = "local.server.com";
else
domain = "production.server.com";
fullDomain = string.Format("https://{0}/WebService/Service.svc", domain);
EndpointAddress endpointAddress = new EndpointAddress(fullDomain);
WebServiceClient client = new WebServiceClient(binding, endpointAddress);
是這個例子用於monotouch?我找不到對WebServiceClient的引用? – JonBull2013
看我的編輯 - 它應該給更多的上下文。我假設你使用傳統的.NET Web服務? – Luke