调用WCF服务失败

发布于 2024-12-04 08:53:26 字数 3028 浏览 0 评论 0原文

我有一个 WCF 服务托管在 IIS 5.1 上,并且禁用了匿名访问。下面是 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>

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

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

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

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

谢谢!

Zen

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

<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>

I have a WCF Service being hosted on IIS 5.1 with Anonymous access disabled. Below is a part of the web.config file showing how the service is configured:

<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>

Every time I call any operations that this service exposes from a desktop application, I receive the following error message:

Either a required impersonation level was not provided, or the
provided impersonation level is invalid.

Please note that binding type and hosting environment is pre-determined by the client and cannot be changed.

Any help that may lead to resolving this issue would be greatly appreciated.

Thanks!

Zen

EDIT: Here is how the client is configured:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无言温柔 2024-12-11 08:53:26

尝试传递当前用户的 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

Try this to pass the current users Windows credentials:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文