c# - How to call a service using multiple Endpoint URIs -
to put context, have client application attempt call webservice deployed on multiple web servers. uri list obtained settings.settings
file of client , foreach loop cycle through uris until available service responds.
let's have service following contract:
[servicecontract] public interface icmmsmanagerservice { [operationcontract] serverinfo getserverinfo(string systemnumber); }
in web.config of service's project, have defined cmmsmanager
service the endpoint name: basichttpbinding_iworkloadmngrservice
<system.servicemodel> <services> <service name="workloadmngr"> <endpoint binding="basichttpbinding" contract="imetadataexchange" /> </service> <service name="cmmsmanager"> <endpoint binding="basichttpbinding" contract="imetadataexchange" name="basichttpbinding_iworkloadmngrservice" /> </service> </services> <client> <remove contract="imetadataexchange" name="sb" /> </client> <behaviors> <servicebehaviors> <behavior> <servicemetadata httpgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="true" /> </behavior> </servicebehaviors> </behaviors> <bindings> <basichttpbinding> <binding> <security mode="transportcredentialonly"> <transport clientcredentialtype="windows"/> </security> </binding> </basichttpbinding> </bindings> <servicehostingenvironment multiplesitebindingsenabled="true" /> </system.servicemodel>
on client side, have following code executed when application starts:
private void querywebserviceurls() { var webserviceurls = properties.settings.default.webserviceurls; foreach (var webserviceurl in webserviceurls) { try { var client = new cmmsmanagerserviceclient("basichttpbinding_iworkloadmanagerservice"); client.endpoint.address = new endpointaddress(new uri(webserviceurl), client.endpoint.address.identity, client.endpoint.address.headers); client.open(); var result = client.getserverinfo("test"); } catch (endpointnotfoundexception e) { continue; } catch (invalidoperationexception e) { break; } } }
but application crashes invalidoperationexception
when cmmsmanagerserviceclient
class instanciated.
could not find endpoint element name 'basichttpbinding_iworkloadmngrservice' , contract 'comclientservice.icmmsmanagerservice' in servicemodel client configuration section. might because no configuration file found application, or because no endpoint element matching name found in client element.
i have following configuration in app.config:
<system.servicemodel> <bindings> <basichttpbinding> <binding name="basichttpbinding_icmmsmanagerservice"> <security mode="transportcredentialonly"> <transport clientcredentialtype="windows" /> </security> </binding> </basichttpbinding> </bindings> <client> <endpoint address="http://localhost/workloadmngr/cmmsmanagerservice.svc" binding="basichttpbinding" bindingconfiguration="basichttpbinding_icmmsmanagerservice" contract="comclientservice.icmmsmanagerservice" name="basichttpbinding_icmmsmanagerservice" /> </client> </system.servicemodel>
i thought valid passing basichttpbinding_icmmsmanagerservice
parameter cmmsmanagerserviceclient
class. have no clue missing @ moment... ideas?
the error telling what's wrong: there no endpoint name basichttpbinding_iworkloadmngrservice
. app.config says endpoint called basichttpbinding_icmmsmanagerservice
code should be:
var client = new cmmsmanagerserviceclient("basichttpbinding_icmmsmanagerservice");
hope helps.
Comments
Post a Comment