【问题标题】:Getting blank page trying to see WSDL from WCF service获取空白页面尝试从 WCF 服务查看 WSDL
【发布时间】:2016-09-06 15:08:28
【问题描述】:

当我使用 VS 生成客户端代理时,我可以连接到托管在 IIS 上的 WCF 服务,但是当我通过浏览器查看时,我得到一个空白页面,当我附加 ?WSDL 时也是如此。我究竟做错了什么?我需要查看 WSDL

我的服务接口

[ServiceContract]
public interface IObjectService
{
    [OperationContract]
    [WebInvoke(
        Method = "POST",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "/GetTrade"
        )]
    GetTradeResponse GetTrade(GetTradeRequest request);
}

还有我的 web.config

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ObjectServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <!-- This section is optional with the default configuration         model introduced in .NET Framework 4 -->
      <service name="ObjectServiceApi.ObjectService" behaviorConfiguration="ObjectServiceBehaviour">

        <!-- This endpoint is exposed at the base address provided by host:http://localhost/ObjectService.svc  -->
        <endpoint address="" 
                  binding="basicHttpBinding"
          bindingConfiguration="BasicHttpEndpointBinding"
                  contract="ObjectServiceApi.Interface.IObjectService" />

      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

【问题讨论】:

  • 您调用的 URL 是什么?也许您在 URL 上有一个结尾 slash? /,如下所示:http://localhost:PORT/ObjectService.svc/
  • 10.220.175.59:8085/ObjectService.svc - 我试过带和不带斜线。是否可以打开某种 IIS 跟踪以查看是否抛出任何错误?
  • 你可以尝试设置security mode="None"transport clientCredentialType="None"。可能是认证有问题。
  • 另一个想法是完全删除&lt;services /&gt; 部分并将&lt;binding name="BasicHttpEndpointBinding"&gt; 更改为&lt;binding&gt; 因为您不需要这些属性,除非您想修改端点(这可能是问题)。
  • 我认为您可能对身份验证有所了解。我只记得我最近删除了对匿名开放的 MEX 端点,但我的标准服务需要 Windows 身份验证。由于删除了我的 MEX 端点,我无法再通过 VS 连接到该服务,它给出了 401 未经授权的异常。如何在锁定我的服务的同时公开 WSDL?

标签: c# wcf soap wsdl


【解决方案1】:

请确保在 IIS 中您已在应用程序上启用授权方法。

如果您将web.config 更改为以下内容,我几乎(!)确信您可以调用您的 WSDL:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding>
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <protocolMapping>
      <add scheme="http" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"/>
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration> 

【讨论】:

  • protocolMappings 和 webserver 块有什么作用?当然,我仍然需要为 IIS 指定一个端点,否则 IIS 将如何知道服务在哪里?
  • protocolMapping 定义了哪个协议必须使用哪个绑定。 webServer 部分实际上是不需要的(从我的web.config 复制)。您不必在 web.config 中指定端点。如果您没有定义,IIS 会自动为您处理。
  • 如果您使用basicHttpBinding,则不需要&lt;protocalMapping&gt; 元素,因为这是http 上的WCF 的默认值。
  • 谢谢@Tim 不知道!
猜你喜欢
  • 1970-01-01
  • 2017-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-13
  • 1970-01-01
相关资源
最近更新 更多