无法调用WCF服务

时间:2011-09-14 19:01:32

标签: wcf basichttpbinding

我在IIS 5.1上托管了WCF服务,禁用了匿名访问。下面是web.config文件的一部分,显示了服务的配置方式:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="basicHttpBindingCfg">
            <security mode="TransportCredentialOnly">
               <transport clientCredentialType="Windows" />
            </security>
         </binding>
      </basicHttpBinding>
   </bindings>
   <services>
      <service behaviorConfiguration="ServiceBehavior" name="HelloService">
         <endpoint name="BasicHttpEndpoint" 
             address="" 
             binding="basicHttpBinding" 
             bindingConfiguration="basicHttpBindingCfg"
             contract="IHelloService">
         </endpoint>
         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
   </services>
   <behaviors>
      <serviceBehaviors>
         <behavior name="ServiceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior>
      </serviceBehaviors>
   </behaviors>
</system.serviceModel>

每次我调用此服务从桌面应用程序公开的任何操作时,都会收到以下错误消息:

  

未提供所需的模拟级别,或者   如果假冒级别无效。

请注意,绑定类型和托管环境由客户预先确定,无法更改。

任何可能导致解决此问题的帮助都将不胜感激。

谢谢!

编辑:以下是客户端的配置方式:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="BasicHttpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            <security mode="TransportCredentialOnly">
               <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
               <message clientCredentialType="UserName" algorithmSuite="Default" />
            </security>
         </binding>
      </basicHttpBinding>
   </bindings>
   <client>
      <endpoint name="BasicHttpEndpoint" 
          address="http://vm00000033871b.intra.pri/WCFServiceBasicHttp/HelloService.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpEndpoint"
          contract="Proxy.IHelloService" />
   </client>
</system.serviceModel>

1 个答案:

答案 0 :(得分:3)

尝试此操作以传递当前用户的Windows凭据:

Using proxy As New PRX.HelloServiceClient()
    proxy.ClientCredentials.Windows.AllowedImpersonationLevel = 
                                       TokenImpersonationLevel.Impersonation
    proxy.ChannelFactory.Credentials.Windows.ClientCredential = 
                                       CredentialCache.DefaultNetworkCredentials
    Dim message As String = proxy.Hello("Hi")
    MessageBox.Show(message)
End Using