Hari Gillala
Hari Gillala

Reputation: 11926

WCF Hosted in IIS 7.0 Binding Issue

I have hosted a WCF Service on IIS7 by creating a WCFService Application Project Type.

In WCF Service Solution, there are two Project. 1) Actual *WCFService* *and 2) WCFService Application* for hosting it in IIS7.0

1) Actual WCFService Project. app.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="DHDocuments.DService">
        <endpoint address="" binding="wsHttpBinding" 
                  contract="DHDocuments.IDService" >
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" 
                  contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
           <add baseAddress="http://localhost:8732/Design_Time_Addresses/DHDocuments/DService/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

2) WCFService Application web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="DHDocuments.DService">
        <endpoint address="" binding="basicHttpBinding" 
                  bindingConfiguration="" 
                  name="basic" 
                  contract="DHDocuments.IDService"/>
      </service>
    </services>
    <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>

In the IIS its being hosted. Its available at http://localhost:2004/DService.svc

Now Coming to the WCF Consuming Project,

I have added a Service Reference by Pointing to the http://localhost:2004/DService.svc. In my WCF Consuming client project this is the app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint address="http://localhost:2004/DService.svc" 
                binding="basicHttpBinding"
                bindingConfiguration="basic1" 
                contract="WCFDHService.IDService"
                name="basic" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="basic1" closeTimeout="00:01:00" 
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00" 
                 sendTimeout="00:01:00" allowCookies="false"
                 bypassProxyOnLocal="false" 
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="65536" maxBufferPoolSize="524288"
                 maxReceivedMessageSize="65536"
                 messageEncoding="Text" textEncoding="utf-8" 
                 transferMode="Buffered"
                 useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192"
                        maxArrayLength="16384" maxBytesPerRead="4096"
                        maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" 
                       proxyCredentialType="None"
                       realm="" />
            <message clientCredentialType="UserName" 
                     algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>       
  </system.serviceModel>
</configuration>

The binding at system.serviceModel/bindings/basicHttpBinding does not have a configured binding named 'basic1'. This is an invalid value for bindingConfiguration

**

Can someone point what is being missed?

There is no problem when I have utilised wcf service directly by debug mode, without hosting it in IIS. I am sure, the binding config is getting error.

Upvotes: 1

Views: 110

Answers (1)

Ross Bush
Ross Bush

Reputation: 15185

It appears that you have configured your services for metadata discovery with a mex endpoint:

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

Another endpoint in the service configuration is defined as wsHttpBinding:

<endpoint address="" binding="wsHttpBinding" contract="DHDocuments.IDService" >

I am guessing since mex is enabled the client proxy will generate a wsdl, however, you need to specify https if using transport security. Or add a endpoint for basicHttpBinding in your wcf service.

It seems like you are trying to access your service in the client proxy using a basicHttpBinding configuration but the service is not configured to accept or listen for such.

Upvotes: 0

Related Questions