Wcf basicHttpBinding在Windows 8.1应用商店中不起作用

时间:2015-02-10 12:42:37

标签: c# wpf wcf windows-8.1

我写了一个Wcf服务,其配置文件是

  <system.serviceModel>    
      <behaviors>
        <serviceBehaviors>
          <behavior name="MyServiceTypeBehaviors" >
            <serviceMetadata httpGetEnabled="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="securityDemo">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="WcfDemo.EmpService"  behaviorConfiguration="MyServiceTypeBehaviors">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:3003/"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="WcfDemo.IEmpService" bindingConfiguration="securityDemo"/>
      </service>
    </services>
  </system.serviceModel>

这适用于控制台应用或WPF应用。 但是当我在Windows 8.1应用程序中使用相同的服务时,我得到了这个异常

  

HTTP请求未经授权使用客户端身份验证方案   '谈判'。从服务器收到的身份验证标头是   '协商,NTLM'。

1 个答案:

答案 0 :(得分:1)

  • 在IIS Local上部署WCF服务(因为IIS Express不那么灵活),启动匿名身份验证并在Windows集成身份验证上设置。
  • 在目标Win 8应用程序中进行服务引用。
  • 在使用服务代理之前添加带标识的行:

    var client = new ServiceReference1.Service1Client(); client.ClientCredentials.Windows.ClientCredential.UserName =&#34; windows user name&#34 ;;
    client.ClientCredentials.Windows.ClientCredential.Password =&#34; user passw&#34;;

  • 调用服务方法

  • 利润