我在本地IIS服务器上运行了一个WCF服务.我把它作为一个C#Website项目的服务引用添加,它添加了fine并自动生成代理类.

但是,当我try 调用任何服务合同时,我会出现以下错误:

Description:测试期间发生未处理的异常

Exception Details:系统.服务模型.协议例外:

我还有一个控制台应用程序,它也与WCF服务进行通信,控制台应用程序能够在不出现此错误的情况下很好地调用方法.

下面是我的配置文件摘录.

WCF服务网站.配置:

<system.serviceModel>
   <services>
      <service name="ScraperService" behaviorConfiguration="ScraperServiceBehavior">
         <endpoint address=""
                   binding="wsHttpBinding" 
                   bindingConfiguration="WSHttpBinding_IScraperService"
                   contract="IScraperService" />
         <endpoint address="mex" 
                   binding="mexHttpBinding" 
                   contract="IMetadataExchange" />
         <host>
            <baseAddresses>
                <add baseAddress="http://example.com" />
            </baseAddresses>
         </host>
      </service>
   </services>
   <bindings>
       <wsHttpBinding>
           <binding name="WSHttpBinding_IScraperService"
                    bypassProxyOnLocal="false" transactionFlow="false"
                    hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
                    messageEncoding="Text" textEncoding="utf-8"
                    useDefaultWebProxy="true" allowCookies="false">
               <readerQuotas 
                     maxDepth="2000000" maxStringContentLength="2000000" 
                     maxArrayLength="2000000" maxBytesPerRead="2000000"
                     maxNameTableCharCount="2000000" />
               <reliableSession 
                     enabled="false" ordered="true" inactivityTimeout="00:10:00" />
               <security mode="Message">
                   <message clientCredentialType="Windows"
                            negotiateServiceCredential="true"
                            algorithmSuite="Default"
                            establishSecurityContext="true" />
               </security>
            </binding>
          </wsHttpBinding>
      </bindings>
      <behaviors>
          <serviceBehaviors>
              <behavior name="ScraperServiceBehavior">
                  <serviceMetadata httpGetEnabled="true" />
                  <serviceDebug includeExceptionDetailInFaults="true" />
              </behavior>
          </serviceBehaviors>
     </behaviors>
</system.serviceModel>

网站项目服务客户端Web.Config:

<system.serviceModel>
   <bindings>
      <wsHttpBinding>
          <binding name="WSHttpBinding_IScraperService" 
              closeTimeout="00:01:00" openTimeout="00:01:00" 
              receiveTimeout="00:10:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="false" transactionFlow="false" 
              hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
              messageEncoding="Text" textEncoding="utf-8"
              useDefaultWebProxy="true" allowCookies="false">
              <readerQuotas 
                  maxDepth="32" maxStringContentLength="8192" 
                  maxArrayLength="16384" maxBytesPerRead="4096" 
                  maxNameTableCharCount="16384" />
              <reliableSession enabled="false"
                  ordered="true" inactivityTimeout="00:10:00" />
              <security mode="Message">
                  <transport clientCredentialType="Windows" 
                       proxyCredentialType="None" realm="" />
                  <message clientCredentialType="Windows" 
                       negotiateServiceCredential="true"
                       algorithmSuite="Default" />
              </security>
          </binding>
       </wsHttpBinding>
    </bindings>
<client>
        <endpoint name="WSHttpBinding_IScraperService"
            address="http://example.com/ScraperService.svc"
            binding="wsHttpBinding" 
            bindingConfiguration="WSHttpBinding_IScraperService"
            contract="ScraperService.IScraperService" >
           <identity>
               <servicePrincipalName value="host/FreshNET-II" />
           </identity>
        </endpoint>
     </client>
</system.serviceModel>

这是我第一次try 创建WCF,所以它非常新.非常感谢您的帮助.

推荐答案

try 使用客户端正常运行时使用的Windows凭据,在托管服务的服务器上的web浏览器中浏览到http://localhost/ScraperService.svc.

我认为IIS显示的是某种描述的html错误消息,而不是像预期的那样返回xml.

当您有一个执行internet筛选的http代理服务器时,也会发生这种情况.我对ContentKeeper的经验是,它拦截任何http/https流量,并将其作为"非托管内容"进行阻止——我们得到的只是一条html错误消息.为了避免这种情况,您可以将代理服务器例外规则添加到Internet Explorer,以便代理服务器不会拦截到您站点的流量:

Control Panel > Internet Options > Connections > LAN Settings > Advanced > Proxy Settings

在此处输入图像描述

.net相关问答推荐

使用EFCore.BulkExtensions库方法BulkInertOrUpdate时区分插入和更新的记录

使用CLR将数据从Excel导入SQL Server时出错

无法通过构建目标访问 dotnet 的环境变量

NonSerialized 属性

将毫秒转换为人类可读的时间间隔

app.config 文件和 XYZ.settings 文件有什么区别?

我应该从 .NET 中的 Exception 或 ApplicationException 派生自定义异常吗?

DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") 返回上午时间而不是下午时间?

如何授予所有用户对我的应用程序创建的文件的完全权限?

测试没有预期的异常

互锁且易变

在未安装 Visual Studio 的机器上使用 FUSLOGVW.EXE

是否有 Linq 方法可以将单个项目添加到 IEnumerable

如何在 WPF 中的 Xaml 文件中添加注释?

内存分配:堆栈与堆?

如何从 WCF REST 方法返回自定义 HTTP 状态代码?

使用 LINQ 搜索树

如何将 .NET 应用程序编译为本机代码?

如何修改 KeyValuePair 值?

如何将两个 List 相互比较?