Home > Enterprise >  Set WCF Service endpoints at server side web config for https
Set WCF Service endpoints at server side web config for https

Time:01-01

I am stuck in very odd situation and do not know how to solve this issue.

I have very simple WCF service working very fine with http BUT now I want to move it to https.

The issue is Server where it needs to be hosted. Server IIS have an alias name "server-test.local" (not "localhost") with http. Its is accessible locally with this alias name. And its mapped to a Domain name with https (example, https://rmt.XXXXXXX.com).

When I deploy my WCF to that server and check WSDL file, it has mapping of the local alias name instead of public domain name.

it is showing http://server-test.local/WCFService/Service.svc (WRONG)

I want mapping like https://rmt.XXXXXXXX.com/WCFService/Service.svc (CORRECT)

Service web.config

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
   </system.serviceModel>
<system.webServer>    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

When I add service reference to app. It adds following endpoint which is not conrrect.

Client App.config (endpoint)

<endpoint address="http://server-test.local/WCFService/Service.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProcessing"
        contract="WCFService.IService" name="BasicHttpBinding_IProcessing" />

I am able to access the url and WSDL file through browser but not able to consume any Service methods. I am getting error "There is no endpoint which can accept the message."

I think I am missing something obvious here. Please suggest me changes.

CodePudding user response:

You can try to change some simple steps in the web.config file, you can refer to this post for details.
1.Enable transport level security in the web.config file of the service:

<security mode="Transport">
  <transport clientCredentialType="None"/>
</security>

2.Use the bindingConfiguration tag to specify the binding name and the behaviorConfiguration tag to configure the behavior, and then specify the address of the managed service. The code is as follows:

<service name="***" behaviorConfiguration="***">
    <endpoint address= https://rmt.XXXXXXXX.com/WCFService/Service.svc 
      binding="basicHttpBinding"  
      bindingConfiguration="???" 
      contract="WCFService.IService"/>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
  • Related