The*_*lTy 20 wcf basichttpbinding
使用简单的测试Wcf服务使用基本身份验证时遇到一些麻烦.我得到一个例外:
无法激活所请求的服务"http://qld-tgower/test/Service.svc".有关详细信息,请参阅>服务器的诊断跟踪日志.
在跟踪日志中显示:
主机上配置的身份验证方案("基本")不允许在绑定"BasicHttpBinding"("匿名")上配置的身份验证方案.请确保将SecurityMode设置为Transport或TransportCredentialOnly.此外,可以通过IIS管理工具,在<serviceAuthenticationManager>元素的应用程序配置文件中,通过更新绑定上的ClientCredentialType属性,通过ServiceHost.Authentication.AuthenticationSchemes属性更改此应用程序的身份验证方案来解决此问题.或者通过调整HttpTransportBindingElement上的AuthenticationScheme属性.
但是,我不知道,当我我们不正确的用户名和密码,它说,它IS使用基本身份验证?
HTTP请求未经授权使用客户端身份验证方案"Basic".从服务器收到的验证头是'Basic realm ="qld-tgower"'.
这是我的web.config详细信息
<system.serviceModel>
<services>
<service name="WcfService"
behaviorConfiguration="Behavior">
<endpoint address="http://QLD-TGOWER/test/Service.svc"
binding="basicHttpBinding"
bindingConfiguration="httpBinding"
contract="IService" />
</service>
</services>
<diagnostics>
<endToEndTracing activityTracing="false" messageFlowTracing="true" propagateActivity="true"></endToEndTracing>
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="httpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="Basic">
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是我的App.config
<system.serviceModel>
<diagnostics>
<endToEndTracing activityTracing="true" />
<messageLogging logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="Basic"></transport>
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://QLD-TGOWER/test/Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我的测试申请
private static void Main(string[] args)
{
var proxy = new ServiceClient("BasicHttpBinding_IService");
var clientCredentials = proxy.ClientCredentials;
clientCredentials.UserName.UserName = "username";
clientCredentials.UserName.Password = "password";
var res = proxy.GetData(1);
Console.WriteLine(res);
Console.WriteLine("Done");
Console.ReadKey(true);
}
Run Code Online (Sandbox Code Playgroud)
而我的服务
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
Run Code Online (Sandbox Code Playgroud)
这里有什么我想念的吗?
Tre*_*oll 19
更改服务的名称和合同以包含命名空间.
此外,删除端点地址(将其设置为"")并且不在传输标记中包含proxyCredentialType.
web.config的最终结果应该是这样的
<system.serviceModel>
<services>
<service name="MyNameSpace.MyService" behaviorConfiguration="asdf">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="httpBinding" contract="MyNameSpace.IMyService" />
</service>
</services>
<diagnostics>
<endToEndTracing activityTracing="true" messageFlowTracing="true"
propagateActivity="true">
</endToEndTracing>
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="httpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="asdf">
<!-- 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="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)