web services - Create WCF endpoint configurations in the client app, in code? -


i trying consume wcf web service .net client application, , think need able programmatically create endpoints, don't know how. think need because, when try run application, getting following error:

could not find default endpoint element references contract 'iemailservice' in servicemodel client configuration section. might because no configuration file found application, or because no endpoint element matching contract found in client element.

while troubleshooting error, created simple windows forms application, in try consume same web service. test application can connect web service successfully, , valid response. but, can reproduce exact error cited above within in test app removing system.servicemodel node , of child nodes application's app.config file (i might not have remove of section, i'm not sure). so, first thought need add section app.config file real app, , should fine. unfortunately, ridiculous reasons won't here, not option. so, left having generate information in code, inside client app.

i hoping here can me work through this, or can point me toward resource sort of problem.

is possible create endpoint configurations in client app, in code?

by default, when add service reference operation, wcf runtime generate client-side proxy you.

the simplest way use instantiate client proxy constructor takes no parameters, , grab info app.config:

yourserviceclient proxy = new yourserviceclient(); 

this requires config file have <client> entry service contract - if not, you'll error have.

but client side proxy class generated wcf runtime has additional constructors - 1 takes endpoint address , binding, instance:

basichttpbinding binding = new basichttpbinding(securitymode.none); endpointaddress epa = new endpointaddress("http://localhost:8282/basic");  yourserviceclient proxy = new yourserviceclient(binding, epa); 

with setup, no config file @ needed - you're defining in code. of course, can set other properties of binding and/or endpoint here in code.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -