IIS 7.5 Wcf https WSDL 始终返回空白(错误请求)

发布于 2024-11-29 08:04:20 字数 5228 浏览 0 评论 0原文

其他一切工作正常,我可以通过 https 进行 SOAP 和 RESTful 调用,不会出现问题。但 WSDL 总是返回空白(错误的请求)。 HTTP 返回 WSDL 正常。

跟踪日志内部异常报告:

The body of the message cannot be read because it is empty.

serviceMetaData 标记已设置:

<serviceMetadata
httpGetEnabled="true"
policyVersion="Policy15"
httpsGetEnabled="true" />

web.Config 部分 绑定:

    <bindings>
        <basicHttpBinding>
            <binding name="soapBinding">
                <security mode="None">
                </security>
            </binding>
        </basicHttpBinding>
        <webHttpBinding>
            <binding name="webBinding">
                <security mode="None">
                </security>
            </binding>
        </webHttpBinding>
    </bindings>

您会立即注意到安全模式=“无”

通过 ServiceHostFactory 我看到传输模式为:

        ServiceHost serviceHost = new ServiceHost(service.GetType(), baseAddresses);

        if (ExposeSSL(baseAddresses[0]))
        {
            foreach (var endpoint in serviceHost.Description.Endpoints)
            {
                if (endpoint.Binding is WebHttpBinding)
                {
                    ((WebHttpBinding)endpoint.Binding).Security.Mode = WebHttpSecurityMode.Transport;
                    endpoint.Address = new EndpointAddress(baseAddresses[0].ToString().Replace("http", "https"));
                }
                if (endpoint.Binding is BasicHttpBinding)
                {
                    ((BasicHttpBinding)endpoint.Binding).Security.Mode = BasicHttpSecurityMode.Transport;
                    endpoint.Address = new EndpointAddress(baseAddresses[0].ToString().Replace("http", "https"));
                }
            }

服务配置:

        <service name="xxxx.Wcf.AdminJsonService" behaviorConfiguration="DefaultBehaviour">
            <host>
                <baseAddresses>
                    <!-- note, choose an available port-->
                    <add baseAddress="http://localhost:62701/json"/>
                </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior" bindingNamespace="https://www.xxxx/WebService4/AdminJsonService" contract="xxxx.Wcf.IAdminJsonService"/>
        </service>

        <service name="xxxx.Wcf.AdminXmlService" behaviorConfiguration="DefaultBehaviour">
            <host>
                <baseAddresses>
                    <!-- note, choose an available port-->
                    <add baseAddress="http://localhost:62701/xml"/>
                </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="poxBehavior" bindingNamespace="https://www.xxx/WebService4/AdminXmlService" contract="xxxx.Wcf.IAdminXmlService"/>
        </service>

        <service name="xxxx.Wcf.AdminSoapService" behaviorConfiguration="DefaultBehaviour">
            <!-- Service Endpoints -->
            <endpoint binding="basicHttpBinding" behaviorConfiguration="soapBehavior" bindingNamespace="https://www.example.com/WebService4/AdminSoapService" contract="xxxx.Wcf.IAdminSoapService"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>

端点行为

            <!-- SOAP -->
            <behavior name="soapBehavior">
            </behavior>
            <!-- JSON -->
            <behavior name="jsonBehavior">
                <webHttp/>
            </behavior>
            <!-- POX -->
            <behavior name="poxBehavior">
                <webHttp/>
            </behavior>

服务行为

            <behavior name="ErrorBehaviour">
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
            <behavior name="DefaultBehaviour">
                <NiceErrorHandler/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>

                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata
                    httpGetEnabled="true"
                    policyVersion="Policy15"
                    httpsGetEnabled="true" />
            </behavior>

还有

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

人知道为什么会发生这种情况吗?

Everything else works fine, I can make SOAP and RESTful calls w/o issue via https. But WSDL always returns blank (bad request). HTTP returns WSDL fine.

Trace log inner exception reports:

The body of the message cannot be read because it is empty.

serviceMetaData tag is set:

<serviceMetadata
httpGetEnabled="true"
policyVersion="Policy15"
httpsGetEnabled="true" />

web.Config sections
Binding:

    <bindings>
        <basicHttpBinding>
            <binding name="soapBinding">
                <security mode="None">
                </security>
            </binding>
        </basicHttpBinding>
        <webHttpBinding>
            <binding name="webBinding">
                <security mode="None">
                </security>
            </binding>
        </webHttpBinding>
    </bindings>

You will immediately notice security mode="None"

Via ServiceHostFactory I see the mode to transport as:

        ServiceHost serviceHost = new ServiceHost(service.GetType(), baseAddresses);

        if (ExposeSSL(baseAddresses[0]))
        {
            foreach (var endpoint in serviceHost.Description.Endpoints)
            {
                if (endpoint.Binding is WebHttpBinding)
                {
                    ((WebHttpBinding)endpoint.Binding).Security.Mode = WebHttpSecurityMode.Transport;
                    endpoint.Address = new EndpointAddress(baseAddresses[0].ToString().Replace("http", "https"));
                }
                if (endpoint.Binding is BasicHttpBinding)
                {
                    ((BasicHttpBinding)endpoint.Binding).Security.Mode = BasicHttpSecurityMode.Transport;
                    endpoint.Address = new EndpointAddress(baseAddresses[0].ToString().Replace("http", "https"));
                }
            }

Services configuration:

        <service name="xxxx.Wcf.AdminJsonService" behaviorConfiguration="DefaultBehaviour">
            <host>
                <baseAddresses>
                    <!-- note, choose an available port-->
                    <add baseAddress="http://localhost:62701/json"/>
                </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior" bindingNamespace="https://www.xxxx/WebService4/AdminJsonService" contract="xxxx.Wcf.IAdminJsonService"/>
        </service>

        <service name="xxxx.Wcf.AdminXmlService" behaviorConfiguration="DefaultBehaviour">
            <host>
                <baseAddresses>
                    <!-- note, choose an available port-->
                    <add baseAddress="http://localhost:62701/xml"/>
                </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" behaviorConfiguration="poxBehavior" bindingNamespace="https://www.xxx/WebService4/AdminXmlService" contract="xxxx.Wcf.IAdminXmlService"/>
        </service>

        <service name="xxxx.Wcf.AdminSoapService" behaviorConfiguration="DefaultBehaviour">
            <!-- Service Endpoints -->
            <endpoint binding="basicHttpBinding" behaviorConfiguration="soapBehavior" bindingNamespace="https://www.example.com/WebService4/AdminSoapService" contract="xxxx.Wcf.IAdminSoapService"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>

Endpoint behaviours

            <!-- SOAP -->
            <behavior name="soapBehavior">
            </behavior>
            <!-- JSON -->
            <behavior name="jsonBehavior">
                <webHttp/>
            </behavior>
            <!-- POX -->
            <behavior name="poxBehavior">
                <webHttp/>
            </behavior>

Service Behaviours

            <behavior name="ErrorBehaviour">
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
            <behavior name="DefaultBehaviour">
                <NiceErrorHandler/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>

                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata
                    httpGetEnabled="true"
                    policyVersion="Policy15"
                    httpsGetEnabled="true" />
            </behavior>

Also have

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

Anyone have idea's why this may be occurring?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光①夏 2024-12-06 08:04:20

您是否尝试关闭其他端点之一?就我而言,在我禁用其中一个端点之前,WCF 无法工作。我禁用哪一个并不重要。其他人会工作。

    <services>
      <service name="GTW.TrendToolService" behaviorConfiguration="MyServiceBehavior">
        <!--<endpoint name="rest" address="" binding="webHttpBinding" contract="TT.ITrendtoolService" behaviorConfiguration="restBehavior"/>-->
        <endpoint name="json" address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="GTW.IAqvService" />
        <endpoint name="xml" address="xml" binding="webHttpBinding" behaviorConfiguration="restBehavior" contract="GTW.IAqvService" />
        <!--<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="GTW.IAqvService" />
        <endpoint name="soap" address="soap" binding="basicHttpBinding" contract="GTW.IAqvService" />-->
      </service>
    </services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="restBehavior">
      <webHttp />
    </behavior>
    <behavior name="jsonBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>

Did you try turning off one of the other endpoints? In my case WCF didn't work until I disabled one of the endpoints. It didn't matter which one I disabled. The others would work.

    <services>
      <service name="GTW.TrendToolService" behaviorConfiguration="MyServiceBehavior">
        <!--<endpoint name="rest" address="" binding="webHttpBinding" contract="TT.ITrendtoolService" behaviorConfiguration="restBehavior"/>-->
        <endpoint name="json" address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="GTW.IAqvService" />
        <endpoint name="xml" address="xml" binding="webHttpBinding" behaviorConfiguration="restBehavior" contract="GTW.IAqvService" />
        <!--<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="GTW.IAqvService" />
        <endpoint name="soap" address="soap" binding="basicHttpBinding" contract="GTW.IAqvService" />-->
      </service>
    </services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="restBehavior">
      <webHttp />
    </behavior>
    <behavior name="jsonBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>
作妖 2024-12-06 08:04:20

我相信您的问题与您的服务行为部分有关。具体来说,您告诉 .net 以 HTTP 而非 HTTPS 发布您的 WSDL。请尝试以下操作

       <behavior name="DefaultBehaviour">
            <NiceErrorHandler/>
            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
            <serviceDebug includeExceptionDetailInFaults="true"/>

            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata
                httpGetEnabled="true"
                httpsGetEnabled="true"
                policyVersion="Policy15"
                httpsGetEnabled="true" />
        </behavior>

,请注意 serviceMetadata 中引用 httpsGet 而不是 http 的额外行。

我假设在绑定和您的应用程序中都启用了 https,因为您可以看到 http WSDL,而不是一些关于无法找到绑定或其他内容的含糊不清的大字...

I believe your issue is going to be related to your service behaviors section. Specifically you told .net to publish your WSDL in HTTP but not HTTPS. Try the following

       <behavior name="DefaultBehaviour">
            <NiceErrorHandler/>
            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
            <serviceDebug includeExceptionDetailInFaults="true"/>

            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata
                httpGetEnabled="true"
                httpsGetEnabled="true"
                policyVersion="Policy15"
                httpsGetEnabled="true" />
        </behavior>

Note the extra line in the serviceMetadata referring to httpsGet as opposed to http.

I will assume that https is enabled on both the bindings and in your application given that you can see the http WSDL rather than some mumble jumbo about not being able to find bindings or something...

失去的东西太少 2024-12-06 08:04:20

当您进行传输加密时,您必须将 s 添加到您的基地址协议中,例如:<添加 baseAddress="https://localhost:62701/xml"/>或<添加baseAddress =“http://localhost:62701/json”/>

When you are doing the Transport encryption you have to add the s to your base address protocol ex: < add baseAddress="https://localhost:62701/xml"/> or < add baseAddress="http://localhost:62701/json"/>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文