简体   繁体   中英

How to configure WCF services to work through HTTPS without HTTP binding?

I have configured my WCF services to work with SSL but it works ONLY if the HTTP binding exists in the IIS Web Site. When the HTTP binding not exists and exists only HTTPS binding I get the following error:

The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.

How can I resolve this issue?

Thanks.

Modify your configuration this way:

<behaviors>
  <serviceBehaviors>
    <behavior> <!-- behavior can have name (must have name in WCF 3.x) -->
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

您需要使用 mexHTTPSBinding 而不是 mexHTTPBinding

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />

Since you set httpGetEnabled to true, you need to provide a http address. And HTTP binding is a way to provide address. So if you remove it, you need to find another way to provide address. Following are two ways to provide addresses.

HttpGetUrl :

 <serviceMetadata httpGetEnabled="true" httpGetUrl="[your service address]" />

HTTP base address:

 <host>
    <baseAddresses>
       <add baseAddress="[your service address]" />
    </baseAddresses>
 </host>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM