【问题标题】:WCF service on IIS - WSDL is emptyIIS 上的 WCF 服务 - WSDL 为空
【发布时间】:2015-05-05 11:00:59
【问题描述】:

我创建了一个 WCF 服务并将其托管在我的 IIS 服务器上。然后,我需要编辑 schemaLocation。我关注了this post

当我将“?wsdl”添加到 url 时,我得到一个空页面。如果我尝试使用 SOAPui 中的 WSDL 来测试它,我会得到这个“Error loading [http://xx.xxx.xx.xx:8095/CardServiceLib.CardService.svc/service?wsdl]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: Unexpected end of file after无"

如果我删除 HTTPGetUrl,WSDL 是正确的,但 schemaLocation 不是我想要的。使用我使用链接帖子制作的 mod,schemaLocation 是完美的,但 WSDL 是空的……为什么?

这可行,但不是我想要的(生成 WSDL 但链接错误):

<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />

这不是(不生成 WSDL --> 空白页!!!):

<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" httpGetUrl="http://xx.xx.xx.xx.:8095/MyService.svc/endpoint"/>

这是我在 IIS 服务器 7 上的 web.config

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="connectionString" connectionString="server=xxxxx;database=xxxxx;uid=xxxxx;pwd=xxxxx;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="userName" value="admin" />
    <add key="password" value="xxxxx" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
    <add key="SecurityKey" value="xxxxxxxxxx" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <!--<roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>-->
  </system.web>
  <system.serviceModel>
    <standardEndpoints>
        <webHttpEndpoint>
        <!-- the "" standard endpoint is used for auto creating a web endpoint. -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
      </webHttpEndpoint>
    </standardEndpoints>
    <bindings>
      <basicHttpBinding>
        <binding name="SecurityByTransport" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
            <!--<message clientCredentialType="UserName"/>-->
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="CardServiceLib.CardService" behaviorConfiguration="customBehavior">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="SecurityByTransport" name="base" contract="CardServiceLib.ICardService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
        <!--<endpoint address="web" behaviorConfiguration="webHttp" binding="webHttpBinding"
          bindingConfiguration="" name="web" contract="calc.ICalcService">
          <identity>
            <dns value="localhost" />httpGetUrl="http://77.108.40.77:8095/CardServiceLib.CardService.svc/service"
          </identity>
        </endpoint>-->
        <host>
          <baseAddresses>
            <add baseAddress="https://xx.xx.xx.xx:8095/MyService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
        <behavior name="customBehavior">
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" httpGetUrl="http://xx.xx.xx.xx:8095/MyService.Service.svc/service"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="xx,xx" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<protocolMapping>
      <add binding="webHttpBinding" scheme="http"  />
    </protocolMapping>-->
  </system.serviceModel>
      <system.webServer>
        <directoryBrowse enabled="false" />
    </system.webServer>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />  </startup></configuration>

已解决!!我添加了这个

address="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic"

在我的端点标签中,就像写在this link中一样。

【问题讨论】:

    标签: web-services wcf iis soap wsdl


    【解决方案1】:

    我怀疑该问题与访问 WSDL 所需的身份验证有关。

    当尝试直接访问元数据 URL 时,网站会显示以下内容:
    “需要身份验证”
    “服务器http://...:8095 需要用户名和密码。”

    您要么需要提供正确的凭据,要么放宽 WSDL 的权限。

    【讨论】:

    • 但它既不询问用户名也不询问密码.. 看看你自己,这里:77.108.40.77:8095/CardServiceLib.CardService.svc 这个页面运行良好,但尝试使用此页面中的链接转到 wsdl 页面...... .
    • 正如您所指出的,主 .svc 页面不要求提供凭据。但是,WSDL 链接会提示输入凭据。可重复:浏览到提供的 URL,然后单击 svcutil.exe 示例中提供的链接 --> 需要用户身份验证弹出窗口。
    • 我没有任何弹出窗口.. 但是,当我尝试访问 WSDL 时,我看到我有 400 Bad Request。但是,如果我不在 serviceMetadata 标记中使用属性 httpGetUrl,则 WSDL 可以完美运行……我也尝试禁用所需的登录,但仍然没有任何改变……你知道为什么吗?
    • 已解决,如果您有兴趣,请查看我的问题。我将你设置为解决方案,因为无论如何,你帮助了我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多