.net - How to open proxy channel when endpoint defined in config file? -
i work on wcf project.
here contract:
[servicecontract] interface icontract { [operationcontract] string methodtest(string s); [operationcontract] list<hydrants_log_maxtime> getdata(datetime datetime); }
and here how access host service end point:
icontract proxy = channelfactory<icontract>.createchannel(new basichttpbinding(), new endpointaddress("http://localhost/hydrantevents/hydrant.svc")); using (proxy idisposable) { var rows = proxy.getdata(new datetime(2000, 5, 1)); var result = proxy.methodtest("sss"); }
i move definition of end point on client app.config file:
<system.servicemodel> <client> <endpoint address="http://localhost/hydrantevents/hydrant.svc" binding="wshttpbinding" contract="hydrantseventsconsumer.icontract"/> </client> </system.servicemodel>
but when moved definition of end point config file don't know how open proxy channel communicate service host, because don't have proxy instance defined in .config file.
how open proxy channel when endpoint defined in config file?
you can assign value name
attribute in <endpoint>
section of config file, , use overload of channelfactory<t>
takes name value create proxy.
<system.servicemodel> <client> <endpoint address="http://localhost/hydrantevents/hydrant.svc" binding="wshttpbinding" contract="hydrantseventsconsumer.icontract" name="myendpoint" /> </client> </system.servicemodel> icontract proxy = channelfactory<icontract>("myendpoint").createchannel();
Comments
Post a Comment