无法从服务中读取WSDL

时间:2012-03-20 16:17:47

标签: c# wcf

我在IIS中使用SSL证书创建了一个WCF服务。我能够看到它的页面,但我不能消耗它。要么我想从网站打开wsdl没有任何反应。当我尝试从客户端创建服务引用时出现错误

  

元数据包含无法解析的引用:   'https://win-1bmal4qsmmk/IPagac/LegalEntityApplicationService.svc?wsdl'。
  无法识别文档格式(内容类型为'text / html;   字符集= UTF-8' )。元数据包含不能的引用   解决:   'https://win-1bmal4qsmmk/IPagac/LegalEntityApplicationService.svc?wsdl'。   没有端点在听   https://win-1bmal4qsmmk/IPagac/LegalEntityApplicationService.svc?wsdl   那可以接受这个消息。这通常是由不正确引起的   地址或SOAP操作。有关更多信息,请参阅InnerException(如果存在)   细节。远程服务器返回错误:(404)Not Found。如果   该服务在当前解决方案中定义,尝试构建   解决方案并再次添加服务引用。

enter image description here

web.config文件

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="DPMembershipConnection" connectionString="Data Source=localhost; Initial Catalog=data; Integrated Security=True; Pooling=False" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <roleManager enabled="true" defaultProvider="DPRoleManager">
      <providers>
        <add name="DPRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="DPMembershipConnection" applicationName="/" />
      </providers>
    </roleManager>
    <authentication mode="Forms" />
    <compilation debug="true" targetFramework="4.0" />
    <membership defaultProvider="DPMembership">
      <providers>
        <add applicationName="/" connectionStringName="DPMembershipConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="4" name="DPMembership" passwordStrengthRegularExpression="" type="System.Web.Security.SqlMembershipProvider" />
      </providers>
    </membership>
  </system.web>
  <system.serviceModel>
    <bindings>
      <ws2007HttpBinding>
        <binding name="BindingName">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </ws2007HttpBinding>
    </bindings>
    <services>
      <service name="ApplicationContract.WCFContract.LegalEntityApplicationService">
        <endpoint address="https://localhost/IPagac/LegalEntityService.svc"
          behaviorConfiguration="NewBehavior0" binding="ws2007HttpBinding"
          bindingConfiguration="BindingName" name="Endpoint" contract="ApplicationContract.WCFContract.ILegalEntityApplicationService" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="NewBehavior0" />
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
            roleProviderName="AspNetSqlRoleProvider" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
              membershipProviderName="AspNetSqlMembershipProvider" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

网站根目录中的svc文件

<% @ServiceHost 
Debug="true" 
Language="C#" 
Factory="DP.IPagac.Application.LegalEntityServiceHostFactory" 
Service="ApplicationContract.ProgramLayerContract.LegalEntityApplicationService" %>

1 个答案:

答案 0 :(得分:0)

您正确考虑使用https行

 <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /> 

但除非我遗漏了某些东西,否则没有为消费者提供wsdl的mex端点(由错误指定)。提供其他 mex端点,例如:

<services> 
    <service name="ApplicationContract.WCFContract.LegalEntityApplicationService">    
        <endpoint address="https://localhost/IPagac/LegalEntityService.svc"    
          behaviorConfiguration="NewBehavior0" binding="ws2007HttpBinding"    
          bindingConfiguration="BindingName" name="Endpoint"    
          contract="ApplicationContract.WCFContract.ILegalEntityApplicationService" />    

         <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 

    </service>
</services>