c# - WCF Windows Authentication, local debug ok but not work on server -
on server, running windows authentication wcf application hosted in iis 7:
iis config: windows auth : disabled; anonymous: enabled
<system.servicemodel> <services> <service name="services.accountservice" behaviorconfiguration="myservicetypebehaviors"> <endpoint address="" binding="ws2007httpbinding" bindingconfiguration="accountservicebinding" contract="contracts.iaccountservice" /> </service> </services> <behaviors> <servicebehaviors> <behavior name="myservicetypebehaviors" > <!--<servicedebug includeexceptiondetailinfaults="true"/>--> <servicemetadata httpgetenabled="true" httpgeturl="" /> </behavior> </servicebehaviors> </behaviors> <bindings> <ws2007httpbinding> <binding name="accountservicebinding" > <security mode="message"> <message clientcredentialtype="windows" /> </security> </binding> </ws2007httpbinding> </bindings> </system.servicemodel>
and create mvc4 application following code call wcf service:
ws2007httpbinding mybinding = new ws2007httpbinding(); mybinding.security.mode = securitymode.message; endpointaddress endpoint = new endpointaddress("http://server/accountservice.svc"); accountserviceclient _client = new accountservicesobjects.accountserviceclient(mybinding, endpoint); _client.clientcredentials.windows.clientcredential.username = "username"; _client.clientcredentials.windows.clientcredential.password = "password"; var user = _client.getuserinformation(); // works fine
after finished mvc4 application, deploy website same server running wcf one, when login, occurs:
system.servicemodel.security.securitynegotiationexception: caller not authenticated service. system.servicemodel.faultexception:the request security token not satisfied because authentication failed. on system.servicemodel.security.securityutils.throwifnegotiationfault(message message, endpointaddress target) on system.servicemodel.security.sspinegotiationtokenprovider.getnextoutgoingmessagebody(message incomingmessage, sspinegotiationtokenproviderstate sspistate)
how happend?
it seems service hasn't been started @ all. if enable tracing can find exception. there error in configuration - have no base address, have set httpgeturl true (for option have set base address)
this should work you:
<service name="services.accountservice" behaviorconfiguration="myservicetypebehaviors"> <endpoint address="accountservice.svc" binding="ws2007httpbinding" bindingconfiguration="accountservicebinding" contract="services.iaccountservice" /> <host> <baseaddresses> <add baseaddress="http://localhost:8000/"/> </baseaddresses> </host> </service>
Comments
Post a Comment