此方法一般用于Web,部署环境经常变化导致IP经常变动
例子是Silveright调用同域WCF服务的方法
WordGameServiceClient GetClient() { BasicHttpBinding basicbind = new BasicHttpBinding(BasicHttpSecurityMode.None); BinaryMessageEncodingBindingElement binE = new BinaryMessageEncodingBindingElement(); CustomBinding bind = new CustomBinding(basicbind); bind.Elements.Add(binE); EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "../Service/WordGameService.svc")); //也可以自定义绑定,需要和服务绑定对应 //return new WordGameServiceClient(bind, address); return new WordGameServiceClient("CustomBinding_WordGameService", address); }