.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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -