从 ASP.NET 调用 WCF 服务时身份验证失败
平台:VS 2008、.NET 3.5、C#、Oracle 11g
我创建了一个 WCF 服务,它获取一些数据元素,然后将它们插入到数据库表中并返回一个整数。我还创建了一个小型 ASP.NET Web 应用程序来测试该服务。测试 Web 应用程序只有一个包含字段和按钮的页面,单击该按钮实际上会调用 Web 服务来插入数据并返回整数值。
我采取的步骤:
- 构建 WCF 服务
- 发布 WCF 服务
- 使用 svcutil 生成代理类 (.cs) 和 app.config
- 构建测试 asp.net 应用程序并添加在上述步骤中生成的代理类和配置设置。
- 破坏测试应用程序
当我在我的计算机(Windows XP、IIS 5.1)上部署 WCF 和测试 Web 应用程序时,它工作正常。但是,每当我尝试将它们部署到远程服务器上时,它都不起作用。当我尝试使用该服务(部署在远程服务器 - Windows 2003 服务器、IIS 6 上)时,出现以下错误:
无法满足对安全令牌的请求,因为 身份验证失败。
描述:执行期间发生未处理的异常 当前的网络请求。请查看堆栈跟踪以了解更多信息 有关错误及其在代码中的来源的信息。
异常详细信息:System.ServiceModel.FaultException:请求 由于身份验证失败,无法满足安全令牌的要求。
以下是 .config 文件内容:
调用 ASP.NET Web 应用程序(消费者)的 Web.Config 的 wcf 部分:
<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>
WCF 的 Web.Config:
<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>
Platform: VS 2008, .NET 3.5, C#, Oracle 11g
I've created a WCF service which takes some data elements and then inserts them into a database table and returns an integer. I've also created a small ASP.NET web app to test that service. The test web app only has a page with the fields and a button, clicking that button actually calls the web service to insert the data and return a integer value.
The steps I took:
- Build the WCF service
- Publish the WCF Service
- Generate the proxy class (.cs) and app.config using svcutil
- Build the test asp.net app and add the proxy class and config settings as generated on the above step.
- Ruin the test app
It works fine when I deploy both the WCF and the test web app on my computer - Windows XP, IIS 5.1. But, whenever I'm trying to deploy them on a remote server it doesn't work. When I'm trying to consume the service (deployed on remote server - Windows 2003 server, IIS 6) I'm getting the following error:
The request for security token could not be satisfied because
authentication failed.Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.Exception Details: System.ServiceModel.FaultException: The request for
security token could not be satisfied because authentication failed.
Following are the .config files content:
wcf section of the Web.Config of calling ASP.NET web app (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 of the 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能与wcf服务的安全配置有关,具体来说,Windows凭据类型需要有效的域用户名和密码信息。
尝试在客户端提供以下属性;
Could be related with security configuration of wcf service, to be specific, Windows credential type requires valid domain username and password information.
Try providing the following attributes on clientside;