.net - Consume WCF service in winform, how to dynamically set Endpoint element and contract -


i have build test wcf service service1.svc have added service reference of service winform. working , can consume wcf service in winform. got major problem :

  1. when rename or delete 'myproject.exe.config' file. showing error ' not find endpoint element name basichttpbinding_iservice1 , contract servicereferenct1.iservice1

    since 'myproject.exe.config' file contains binding , endpoint address don't want share client or anyone.

    there way dynamically set endpoint element , contract without using 'myproject.exe.config' file ? enter image description here

app.config :

<?xml version="1.0" encoding="utf-8" ?> <configuration>     <startup>         <supportedruntime version="v4.0" sku=".netframework,version=v4.0,profile=client" />     </startup>     <system.servicemodel>         <bindings>             <basichttpbinding>                 <binding name="basichttpbinding_iservice1" />             </basichttpbinding>         </bindings>          <client>             <endpoint  address="http://svc.phed.net/service1.svc" binding="basichttpbinding"                 bindingconfiguration="basichttpbinding_iservice1" contract="servicereference1.iservice1"                 name="basichttpbinding_iservice1" />         </client>     </system.servicemodel> </configuration> 
  1. how can change default message shown service:

    you have created service. test service, need create client , use call service. can using svcutil.exe tool command line following syntax:

if don't have service configuration, can create proxy manually.

here example:

var binding = new basichttpbinding();                 var endpoint = new endpointaddress("yourendpoint");                 var channelfactory = new channelfactory<yourinterface>(binding, endpoint);                  yourinterface client = null;                 client = channelfactory.createchannel();                 client.youroperation(); 

in above example, i've used basichttpbinding. if you're using binding, use right class, instance nettcpbinding.

if handle service in try/catch block can able handle error , throw friendly message client.

hope helps.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -