无法使用基本身份验证HTTPS添加WCF引用

时间:2014-07-04 01:18:54

标签: c# wcf authentication https

我制作了一个WCF服务:HelloWorldService遵循Implement HelloWorld Service中的提示,然后在IIS 8.5(Windows 8.1)中托管基本身份验证enter image description here

和我的web.config

<?xml version="1.0"?>

<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>

  <system.serviceModel>
    <serviceHostingEnvironment >
      <serviceActivations>
        <add factory="System.ServiceModel.Activation.ServiceHostFactory"
        relativeAddress="./HelloWorldService.svc"
        service="MyWCFServices.HelloWorldService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpsGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="MyWCFServices.HelloWorldService">
        <endpoint address="" binding="basicHttpBinding"
        contract="MyWCFServices.IHelloWorldService"
        bindingConfiguration="secureHttpBinding">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding"
        contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name ="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

我在浏览器中尝试成功并使用我的用户名和密码登录。有效 enter image description here

但是当我添加服务引用时出错,我不能在VS2013上使用相同的用户名和密码。 enter image description here 我用用户名和密码多次尝试,但我再次返回对话框 enter image description here 我必须点击否。

这是详细信息:

  

下载时出错   https://localho.st/HelloWorldSecure/HelloWorldService.svc/_vti_bin/ListData.svc/ $元   请求失败,HTTP状态为400:错误请求。元数据   包含无法解析的引用:   https://localho.st/HelloWorldSecure/HelloWorldService.svc   HTTP请求未经授权使用客户端身份验证方案   '匿名'。从服务器收到的身份验证标头是   '基本领域= mylocalhost'。远程服务器返回错误:(401)   未经授权。如果在当前解决方案中定义了服务,请尝试   构建解决方案并再次添加服务引用。

有人帮助我正确地做到了。非常感谢!

0 个答案:

没有答案
相关问题