c# - 调用者未经服务验证

标签 c# asp.net wcf wcf-data-services wcf-client

我正在使用 WCF 并发现此错误:

" The caller was not authenticated by the service."

我在 client.config 文件中使用了此代码:

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSDualHttpBinding_IReceiverController" closeTimeout="00:00:05"
         openTimeout="00:00:05" receiveTimeout="00:10:00" sendTimeout="00:00:05"
         bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
         maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
         messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" />
          <security mode="None">
            <message clientCredentialType="Windows" negotiateServiceCredential="false" />
          </security>
        </binding>
        <binding name="WSHttpBinding_IEMRProWCFService" />
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://pionbuggs-pc:4567/EMRProWCFService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEMRProWCFService"
        contract="EMRProWCFService.IEMRProWCFService" name="WSHttpBinding_IEMRProWCFService">
        <identity>
          <dns value="http://pionbuggs-pc:4567/EMRProWCFService.svc" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

下面是 service.config 文件中的代码:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.web>
    <compilation />
    <httpRuntime maxRequestLength="2147483647" />

  </system.web>

  <system.serviceModel>
    <services>
      <service name="WCFService.EMRProWCFService">
        <endpoint address="" binding="wsHttpBinding" contract="WCFService.IEMRProWCFService">
          <identity>
            <dns value="http://pionbuggs-pc:4567/EMRProWCFService.svc" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <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" />
    <bindings>
      <webHttpBinding>
        <binding name="WebConfiguration" maxBufferSize="65536" maxReceivedMessageSize="2147483647" transferMode="Streamed">
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>

</configuration>

最佳答案

不要使用 binding="wsHttpBinding",而是尝试仅使用基本的,将客户端端点更改为:

<endpoint address="http://pionbuggs-pc:4567/EMRProWCFService.svc"
    binding="basicHttpBinding" bindingConfiguration="WSHttpBinding_IEMRProWCFService"
    contract="EMRProWCFService.IEMRProWCFService" name="WSHttpBinding_IEMRProWCFService">

以及您的服务:

<endpoint address="" binding="basicHttpBinding" contract="WCFService.IEMRProWCFService">

错误在于您使用的高级安全性要求您使用身份验证,除非存在需要它的安全约束。

以下是有关它的一些信息:

BasicHttpBinding vs WsHttpBinding vs WebHttpBinding

关于c# - 调用者未经服务验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14027889/

相关文章:

c# - Couchbase 错误打开存储桶 - 无法引导

c# - 从目录和子目录中获取文件,按最新创建日期快速排序

c# - Json.net LinearGradientBrush序列化

wcf - 为什么我们需要 WCF

wcf - 如何处理低级 WCF 错误?

c# - 当默认配置已经存储在其他地方时,是否不需要对默认配置进行硬编码?

c# - 快速多字符串替换

asp.net - 尝试创建角色时,列名区分符无效

c# - ObjectDataSource 找不到非泛型方法

javascript - 执行了 ajax 请求。如何格式化返回的数据?