Authentication failed when calling WCF service from ASP.NET

Platform: VS 2008, .NET 3.5, C #, Oracle 11g

I created a WCF service that takes some data items and then inserts them into a database table and returns an integer. I also created a small ASP.NET web application to test this service. In the test web application, there is only a page with fields and a button, clicking this button actually calls the web service to insert data and return an integer value.

The steps I took:

  • Create a WCF Service
  • Publish WCF Service
  • Generate proxy class (.cs) and app.config using svcutil
  • Create an asp.net test application and add the proxy settings and configurations that you created in the previous step.
  • Destroy test application

It works great when I deploy both WCF and a test web application on my computer - Windows XP, IIS 5.1. But, when I try to deploy them to a remote server, this will not work. When I try to use a service (deployed on a remote server - Windows 2003 server, IIS 6), I get the following error:

The request for the security token cannot be satisfied because the authentication failed.

Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for error information and where it originated in the code.

Exception Details: System.ServiceModel.FaultException: The security token request could not be satisfied because authentication failed.

The following is a list of .config files:

wcf section in Web.Config to invoke ASP.NET web application (Consumer):

<system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IMyWCFService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Message"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" /> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://57.23.85.28:8001/MyWCFService/MyWCFService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyWCFService" contract="IMyWCFService" name="WSHttpBinding_IMyWCFService"> <identity> <dns value="localhost" /> </identity> </endpoint> </client> </system.serviceModel> 

Web.Config WCF:

 <configuration> <connectionStrings> <add name="DSMyWCF" connectionString="Data Source=XXX;User id=XXX;Password=XXX;"/> </connectionStrings> <system.web> <compilation debug="true" /> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <services> <service behaviorConfiguration="MyWCFService.MyWCFServiceBehavior" name="MyWCFService.MyWCFService"> <endpoint address="" binding="wsHttpBinding" contract="MyWCFService.IMyWCFService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:8731/Design_Time_Addresses/MyWCFService/MyWCFService/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyWCFService.MyWCFServiceBehavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="True"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 
+6
source share
1 answer

May be related to wcf service security configuration, to be specific, Windows credential type requires a valid domain username and password.

Try providing the following attributes on clientide;

 proxy.ClientCredentials.Windows.ClientCredential.UserName = "UserName "; proxy.ClientCredentials.Windows.ClientCredential.Password = "Password "; proxy.ClientCredentials.Windows.ClientCredential.Domain = "Domain "; 
+1
source

Source: https://habr.com/ru/post/897777/


All Articles