有沒有辦法以編程方式更改Web服務的<endpoint address="..." />
值?在我的app.config文件,我有以下代碼:以編程方式編輯Web服務的終點
<system.serviceModel>
<bindings>
...
</bindings>
<client>
<endpoint address="http://dev.remotedomain.com/WebServices/WebService.asmx"
binding="basicHttpBinding" bindingConfiguration="InboxServiceSoap"
contract="InboxServiceSoap"
name="InboxServiceSoap" />
</client>
</system.serviceModel>
我希望能夠改變
address="http://dev.remotedomain.com/WebServices/WebService.asmx"
到
address="http://mymachine/WebServices/WebService.asmx"
代碼
。這可能在.NET中編程?
這作品,但讓我懷疑。添加WCF服務引用後,會有六個引用服務URL的項目文件。然後,我將服務移動到不同的URL,添加這行代碼,並且一切正常。似乎不應該編譯? – nuander 2012-06-11 21:31:18
C#:service.Endpoint.Address = new EndpointAddress(myUrl); – 2013-08-20 07:42:00
@nuander編譯很好,只是一個字符串是不同的。只要不同的URL符合相同的協議和格式,也不會有運行時問題。 – 2013-08-20 07:42:56