c# - Error calling WCF webservice through channelfactory - not permissioned -


i using channelfactory call wcf service (as target service location change depending on environment , need url configurable). error:

the http request unauthorized client authentication scheme 'anonymous'. authentication header received server 'negotiate,ntlm'.

my calling code

var mybinding = new basichttpbinding(); var myendpoint = new endpointaddress(webserviceaddress); var mychannelfactory = new channelfactory<iobjectservice>(mybinding, myendpoint); var serviceclient = mychannelfactory.createchannel(); 

my wcf service web.config system.servicemodel section

  <system.servicemodel>     <behaviors>       <servicebehaviors>         <behavior>           <servicemetadata httpgetenabled="true" httpsgetenabled="true"/>           <servicedebug includeexceptiondetailinfaults="true"/>         </behavior>       </servicebehaviors>     </behaviors>     <bindings>       <basichttpbinding>         <binding>           <security mode="transportcredentialonly">             <transport clientcredentialtype="windows"/>           </security>         </binding>       </basichttpbinding>     </bindings>     <protocolmapping>       <add binding="basichttpsbinding" scheme="https" />     </protocolmapping>     <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" minfreememorypercentagetoactivateservice="0" />   </system.servicemodel> 

the service should authenticated based on windows authentication. have thought default calling code above use windows authentication pass account code running (a service account) seems sending anonymous

you must set mode transport message credentials, shown in following code:

var mybinding = new basichttpbinding(); mybinding.security.mode = securitymode.transportcredentialonly; 

as alternative, can set mode in constructor of binding:

var mybinding = new basichttpbinding(securitymode.transportcredentialonly); 

also set clientcredential:

mybinding.security.transport.clientcredentialtype = httpclientcredentialtype.windows; 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -