问题描述
你好..
WCF的新功能.
我遇到以下情况..我的WCF服务需要返回
I got following scenario .. my WCF service need to return
HttpContext .Current.Application [ ; auth_mode"; ] .ToString();
HttpContext.Current.Application["auth_mode"].ToString();
连接到WCF客户端.
我的服务显示为
命名空间 Calumo.Site.WCF
namespace Calumo.Site.WCF
{
//注意:如果您更改类名称"ExcelClientAuthentication",在这里,您还必须更新对"ExcelClientAuthentication"的引用,在Web.config中.
// NOTE: If you change the class name "ExcelClientAuthentication" here, you must also update the reference to "ExcelClientAuthentication" in Web.config.
[ AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode .允许)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
公共 类别 ExcelClientAuthentication : IExcelClientAuthentication
public class ExcelClientAuthentication : IExcelClientAuthentication
{
公共 字符串 AuthenticateExcelClient()
public string AuthenticateExcelClient()
{
var test = OperationContext .Current.ServiceSecurityContext.WindowsIdentity;
var test = OperationContext.Current.ServiceSecurityContext.WindowsIdentity;
var application = HttpContext .Current.Application [ ; auth_mode"; ].ToString();
var application = HttpContext.Current.Application["auth_mode"].ToString();
返回 应用程序;
return application;
}
}
}
< system.serviceModel >
<system.serviceModel>
< serviceHostingEnvironment aspNetCompatibilityEnabled = " 真 " >
<serviceHostingEnvironment aspNetCompatibilityEnabled="True">
</ serviceHostingEnvironment >
</serviceHostingEnvironment>
< 服务 >
<services>
< 服务 behaviorConfiguration = " Calumo.Site.WCF.ExcelClientAuthenticationBehavior "
<service behaviorConfiguration="Calumo.Site.WCF.ExcelClientAuthenticationBehavior"
名称 = " Calumo.Site.WCF.ExcelClientAuthentication " >
name="Calumo.Site.WCF.ExcelClientAuthentication">
<!- 服务端点 ->
<!-- Service Endpoints -->
< 端点 地址 = "" 绑定 = " wsHttpBinding " 合同 = " Calumo.Site.WCF.IExcelClientAuthentication " >
<endpoint address="" binding="wsHttpBinding" contract="Calumo.Site.WCF.IExcelClientAuthentication">
<!-
<!--
部署后,应删除或替换以下标识元素以反映
Upon deployment, the following identity element should be removed or replaced to reflect the
运行已部署服务的身份.如果删除,WCF将推断出适当的身份
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
自动.
->
-->
< 身份 >
<identity>
< dns 值 = " 本地主机 " />
<dns value="localhost"/>
</ 身份 >
</identity>
</ 端点 >
</endpoint>
< 端点 地址 = " mex " 绑定 = " mexHttpBinding " 合约 = " IMetadataExchange " />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</ 服务 >
</service>
</ 服务 >
</services>
< 行为 >
<behaviors>
< serviceBehaviors >
<serviceBehaviors>
< 行为 名称 = " Calumo.Site.WCF.ExcelClientAuthenticationBehavior " >
<behavior name="Calumo.Site.WCF.ExcelClientAuthenticationBehavior">
<!- 为避免泄露元数据信息,请在部署之前将下面的值设置为false并删除上面的元数据端点 ->
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
< serviceMetadata httpGetEnabled = " true " />
<serviceMetadata httpGetEnabled="true"/>
<!- 要在故障中接收异常详细信息以进行调试,请将下面的值设置为true.部署前设置为false以避免泄露异常信息 ->
<!-- 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 " />
<serviceDebug includeExceptionDetailInFaults="false"/>
</ 行为 >
</behavior>
</ serviceBehaviors >
</serviceBehaviors>
</ 行为 >
</behaviors>
</ system.serviceModel >
</system.serviceModel>
客户端:
命名空间 WindowsFormsApplication4
{
公共 部分 class Form1 : 表单
public partial class Form1 : Form
{
公共 Form1()
public Form1()
{
InitializeComponent();
InitializeComponent();
}
私有 无效 Form1_Load( 对象 发件人, EventArgs e)
private void Form1_Load(object sender, EventArgs e)
{
ExcelClientAuthenticationClient excelClient = 新 ExcelClientAuthenticationClient ();
ExcelClientAuthenticationClient excelClient = new ExcelClientAuthenticationClient();
MessageBox .Show(excelClient.AuthenticateExcelClient()+ "" + client.GetData());
MessageBox.Show(excelClient.AuthenticateExcelClient()+" " +client.GetData());
}
}
}
但在 excelClient.AuthenticateExcelClient()-
错误:HTTP请求未经客户端身份验证方案匿名"授权.从服务器收到的身份验证标头是"Negotiate,NTLM".
error: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
非常感谢您的帮助.
Ven
推荐答案
这篇关于HTTP请求未经客户端身份验证方案“匿名"授权.从服务器收到的身份验证标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!