c# - Change URL on ChannelFactory? -
i using channelfactory when connecting client service using wcf :
new channelfactory<t>(endpointconfigurationname);
this load settings config file alot in case. need change url before using channel, how done? not find url on channelfactory? provide endpointaddress while creating channel suspect reset settings configfile?
im using channelfactory avoid generating new proxy every change , able set credentials.
edit :
this how did solved
for(int = 0; < clientsection.endpoints.count; i++) { if(clientsection.endpoints[i].name == endpointconfigurationname) { var endpointaddress = new endpointaddress(clientsection.endpoints[i].address.tostring()); var nethttpbinding = new nethttpbinding(clientsection.endpoints[i].bindingconfiguration); var serviceendpoint = new serviceendpoint(contractdescription.getcontract(typeof(t)), nethttpbinding, endpointaddress); var channelfactory = new channelfactory<t>(serviceendpoint); break; } }
you can use generic wrapper method:
public tproxy createchannel(string newendpointaddress) { _endpointaddress = newendpointaddress; var factory = new channelfactory<tproxy>(new nettcpbinding(), new endpointaddress(newendpointaddress)); return factory.createchannel(); }
Comments
Post a Comment