简体   繁体   中英

WCF Service in IIS bindings

I have inherited a WCF project which is hosted under IIS. Its part of a regular website ie there are human usable pages as well.

The site is configured in IIS with the following 2 bindings:

1: https://www.example.com/ 2: http://www.example.com:8080/

If I visit http://www.example.com:8080/my-service.svc?wsdl I get a WSDL file returned as expected.

If I visit https://www.example.com/my-service.svc?wsdl I get told I need to visit http://www.example.com:8080/my-service.svc?wsdl to create a client.

There is no binding section under system.serviceModel in web.config.

What I want to know is, how does the service know it is associated with the second IIS binding and not the first.

system.ServiceModel follows:

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="FormsAuthBehavior" type="My-WCF.FormsAuthBehaviorExtensionElement, EcobuttonWebService" />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior name="FormsAuthenticated">
          <!--To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment-->
          <serviceMetadata httpGetEnabled="true" />
          <!--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="false" />
          <!--Pre-authenticates client with server to generate FormsAuthentication cookie. Cookie is submitted with each WCF request.-->
          <!--NB: set throwsSecurityExceptions="false" when updating service references in client apps.-->
          <FormsAuthBehavior throwsSecurityExceptions="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <services>
      <service name="My-Service" behaviorConfiguration="FormsAuthenticated" />
    </services>
  </system.serviceModel>

Configure WCF Service for HTTP Transport Security

<bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

Specify your service and service endpoint as shown in the following XML.

<services>
      <service name="MySecureWCFService.Service1">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="MySecureWCFService.IService1"/>

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

Enable httpsGetEnabled

<serviceBehaviors>
<serviceMetadata httpsGetEnabled="true"/>
</serviceBehaviors>

References:

MSDN

Seven simple steps to enable HTTPS on WCF WsHttp bindings

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