获取空白页试图从WCF服务中查看WSDL

时间:2016-09-06 15:08:29

标签: c# wcf soap wsdl

当我使用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>

1 个答案:

答案 0 :(得分:0)

请确保在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>