Error in Protocol Mapping While hosting a WCF service in IIS

[Origin]: http://stackoverflow.com/questions/13123861/error-in-protocol-mapping-while-hosting-a-wcf-service-in-iis

I developed a simple WCF service with VS 2010. And i hosted in the default website in IIS by Adding Application and set the Physical Path

And i tried to browse the .svc file it gives me the following error:

The configuration section ‘protocolMapping’ cannot be read because it is missing a section declaration

Protocol Mapping Error

and I tried many solutions but it doesn’t work

I Created WCF Service Library has an App.config with this:

<?</span><span class="pln">xml version</span><span class="pun">=</span><span class="str">"1.0"</span><span class="pln"> encoding</span><span class="pun">=</span><span class="str">"utf-8"</span> <span class="pun">?></span>
<span class="str"><configuration></span>

  <span class="str"><appSettings></span>
    <span class="pun"><</span><span class="pln">add key</span><span class="pun">=</span><span class="str">"aspnet:UseTaskFriendlySynchronizationContext"</span><span class="pln"> value</span><span class="pun">=</span><span class="str">"true"</span> <span class="pun">/></span>
  <span class="pun"></</span><span class="pln">appSettings</span><span class="pun">></span>
  <span class="pun"><</span><span class="pln">system</span><span class="pun">.</span><span class="pln">web</span><span class="pun">></span>
    <span class="pun"><</span><span class="pln">compilation debug</span><span class="pun">=</span><span class="str">"true"</span> <span class="pun">/></span>
  <span class="pun"></</span><span class="pln">system</span><span class="pun">.</span><span class="pln">web</span><span class="pun">></span>
  <span class="pun"><!--</span> <span class="typ">When</span><span class="pln"> deploying the service library project</span><span class="pun">,</span><span class="pln"> the content of the config file must be added to the host</span><span class="str">'</span><span class="pln">s 
  app</span><span class="pun">.</span><span class="pln">config file</span><span class="pun">.</span> <span class="typ">System</span><span class="pun">.</span><span class="typ">Configuration</span><span class="pln"> does not support config files </span><span class="kwd">for</span><span class="pln"> libraries</span><span class="pun">.</span> <span class="pun">--></span>
  <span class="pun"><</span><span class="pln">system</span><span class="pun">.</span><span class="pln">serviceModel</span><span class="pun">></span>
    <span class="str"><services></span>
      <span class="pun"><</span><span class="pln">service name</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.EvalService"</span><span class="pun">></span>
        <span class="pun"><</span><span class="pln">clear </span><span class="pun">/></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"basic"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"basicHttpBinding"</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.IEvalService"</span><span class="pln">
          listenUriMode</span><span class="pun">=</span><span class="str">"Explicit"</span><span class="pun">></span>
          <span class="str"><identity></span>
            <span class="pun"><</span><span class="pln">dns value</span><span class="pun">=</span><span class="str">"localhost"</span> <span class="pun">/></span>
            <span class="pun"><</span><span class="pln">certificateReference storeName</span><span class="pun">=</span><span class="str">"My"</span><span class="pln"> storeLocation</span><span class="pun">=</span><span class="str">"LocalMachine"</span><span class="pln">
              x509FindType</span><span class="pun">=</span><span class="str">"FindBySubjectDistinguishedName"</span> <span class="pun">/></span>
          <span class="pun"></</span><span class="pln">identity</span><span class="pun">></span>
        <span class="pun"></</span><span class="pln">endpoint</span><span class="pun">></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"mex"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"mexHttpBinding"</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"IMetadataExchange"</span><span class="pln">
          listenUriMode</span><span class="pun">=</span><span class="str">"Explicit"</span><span class="pun">></span>
          <span class="str"><identity></span>
            <span class="pun"><</span><span class="pln">dns value</span><span class="pun">=</span><span class="str">"localhost"</span> <span class="pun">/></span>
            <span class="pun"><</span><span class="pln">certificateReference storeName</span><span class="pun">=</span><span class="str">"My"</span><span class="pln"> storeLocation</span><span class="pun">=</span><span class="str">"LocalMachine"</span><span class="pln">
              x509FindType</span><span class="pun">=</span><span class="str">"FindBySubjectDistinguishedName"</span> <span class="pun">/></span>
          <span class="pun"></</span><span class="pln">identity</span><span class="pun">></span>
        <span class="pun"></</span><span class="pln">endpoint</span><span class="pun">></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"ws"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"wsHttpBinding"</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.IEvalService"</span><span class="pln">
          listenUriMode</span><span class="pun">=</span><span class="str">"Explicit"</span><span class="pun">></span>
          <span class="str"><identity></span>
            <span class="pun"><</span><span class="pln">dns value</span><span class="pun">=</span><span class="str">"localhost"</span> <span class="pun">/></span>
            <span class="pun"><</span><span class="pln">certificateReference storeName</span><span class="pun">=</span><span class="str">"My"</span><span class="pln"> storeLocation</span><span class="pun">=</span><span class="str">"LocalMachine"</span><span class="pln">
              x509FindType</span><span class="pun">=</span><span class="str">"FindBySubjectDistinguishedName"</span> <span class="pun">/></span>
          <span class="pun"></</span><span class="pln">identity</span><span class="pun">></span>
        <span class="pun"></</span><span class="pln">endpoint</span><span class="pun">></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"net.tcp://localhost:8888/evalservice"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"netTcpBinding"</span><span class="pln">
          contract</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.IEvalService"</span><span class="pln"> listenUriMode</span><span class="pun">=</span><span class="str">"Explicit"</span><span class="pun">></span>
          <span class="str"><identity></span>
            <span class="pun"><</span><span class="pln">dns value</span><span class="pun">=</span><span class="str">"localhost"</span> <span class="pun">/></span>
            <span class="pun"><</span><span class="pln">certificateReference storeName</span><span class="pun">=</span><span class="str">"My"</span><span class="pln"> storeLocation</span><span class="pun">=</span><span class="str">"LocalMachine"</span><span class="pln">
              x509FindType</span><span class="pun">=</span><span class="str">"FindBySubjectDistinguishedName"</span> <span class="pun">/></span>
          <span class="pun"></</span><span class="pln">identity</span><span class="pun">></span>
        <span class="pun"></</span><span class="pln">endpoint</span><span class="pun">></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"net.pipe://localhost/evalservice"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"netNamedPipeBinding"</span><span class="pln">
          bindingConfiguration</span><span class="pun">=</span><span class="str">""</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.IEvalService"</span> <span class="pun">/></span>
        <span class="str"><host></span>
          <span class="str"><baseAddresses></span>
            <span class="pun"><</span><span class="pln">add baseAddress</span><span class="pun">=</span><span class="str">"http://localhost:8080/evalservice"</span> <span class="pun">/></span>
          <span class="pun"></</span><span class="pln">baseAddresses</span><span class="pun">></span>
        <span class="pun"></</span><span class="pln">host</span><span class="pun">></span>
      <span class="pun"></</span><span class="pln">service</span><span class="pun">></span>
    <span class="pun"></</span><span class="pln">services</span><span class="pun">></span>
    <span class="str"><behaviors></span>
      <span class="str"><serviceBehaviors></span>
        <span class="str"><behavior></span>
          <span class="pun"><!--</span> <span class="typ">To</span><span class="pln"> avoid disclosing metadata information</span><span class="pun">,</span> 
          <span class="typ">set</span><span class="pln"> the values below to </span><span class="kwd">false</span><span class="pln"> before deployment </span><span class="pun">--></span>
          <span class="pun"><</span><span class="pln">serviceMetadata httpGetEnabled</span><span class="pun">=</span><span class="str">"True"</span><span class="pln"> httpsGetEnabled</span><span class="pun">=</span><span class="str">"True"</span><span class="pun">/></span>
          <span class="pun"><!--</span> <span class="typ">To</span><span class="pln"> receive exception details </span><span class="kwd">in</span><span class="pln"> faults </span><span class="kwd">for</span><span class="pln"> debugging purposes</span><span class="pun">,</span> 
          <span class="typ">set</span><span class="pln"> the value below to </span><span class="kwd">true</span><span class="pun">.</span>  <span class="typ">Set</span><span class="pln"> to </span><span class="kwd">false</span><span class="pln"> before deployment 
          to avoid disclosing exception information </span><span class="pun">--></span>
          <span class="pun"><</span><span class="pln">serviceDebug includeExceptionDetailInFaults</span><span class="pun">=</span><span class="str">"False"</span> <span class="pun">/></span>
        <span class="pun"></</span><span class="pln">behavior</span><span class="pun">></span>
      <span class="pun"></</span><span class="pln">serviceBehaviors</span><span class="pun">></span>
    <span class="pun"></</span><span class="pln">behaviors</span><span class="pun">></span>
  <span class="pun"></</span><span class="pln">system</span><span class="pun">.</span><span class="pln">serviceModel</span><span class="pun">></span>
<span class="pun"></</span><span class="pln">configuration</span><span class="pun">>

and i Hosted the WCF Service Library application in WCF website (My Client) has an Web.config with this:

<?</span><span class="pln">xml version</span><span class="pun">=</span><span class="str">"1.0"</span><span class="pun">?></span>
<span class="str"><configuration></span>

  <span class="str"><appSettings></span>
    <span class="pun"><</span><span class="pln">add key</span><span class="pun">=</span><span class="str">"aspnet:UseTaskFriendlySynchronizationContext"</span><span class="pln"> value</span><span class="pun">=</span><span class="str">"true"</span> <span class="pun">/></span>
  <span class="pun"></</span><span class="pln">appSettings</span><span class="pun">></span>
  <span class="pun"><</span><span class="pln">system</span><span class="pun">.</span><span class="pln">web</span><span class="pun">></span>
    <span class="pun"><</span><span class="pln">compilation debug</span><span class="pun">=</span><span class="str">"false"</span><span class="pln"> targetFramework</span><span class="pun">=</span><span class="str">"4.5"</span> <span class="pun">/></span>
    <span class="pun"><</span><span class="pln">httpRuntime targetFramework</span><span class="pun">=</span><span class="str">"4.5"</span><span class="pun">/></span>
  <span class="pun"></</span><span class="pln">system</span><span class="pun">.</span><span class="pln">web</span><span class="pun">></span>
  <span class="pun"><</span><span class="pln">system</span><span class="pun">.</span><span class="pln">serviceModel</span><span class="pun">></span>
    <span class="str"><services></span>
      <span class="pun"><</span><span class="pln">service name</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.EvalService"</span><span class="pun">></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">""</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"wsHttpBinding"</span><span class="pln"> bindingConfiguration</span><span class="pun">=</span><span class="str">""</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.IEvalService"</span> <span class="pun">/></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"mex"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"mexHttpBinding"</span><span class="pln"> bindingConfiguration</span><span class="pun">=</span><span class="str">""</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"IMetadataExchange"</span> <span class="pun">/></span>
        <span class="pun"><</span><span class="pln">endpoint address</span><span class="pun">=</span><span class="str">"basic"</span><span class="pln"> binding</span><span class="pun">=</span><span class="str">"basicHttpBinding"</span><span class="pln"> bindingConfiguration</span><span class="pun">=</span><span class="str">""</span><span class="pln"> contract</span><span class="pun">=</span><span class="str">"EvalServiceLibrary.IEvalService"</span> <span class="pun">/></span>
      <span class="pun"></</span><span class="pln">service</span><span class="pun">></span>
    <span class="pun"></</span><span class="pln">services</span><span class="pun">></span>
    <span class="str"><behaviors></span>
      <span class="str"><serviceBehaviors></span>
        <span class="str"><behavior></span>
          <span class="pun"><!--</span> <span class="typ">To</span><span class="pln"> avoid disclosing metadata information</span><span class="pun">,</span> <span class="typ">set</span><span class="pln"> the values below to </span><span class="kwd">false</span><span class="pln"> before deployment </span><span class="pun">--></span>
          <span class="pun"><</span><span class="pln">serviceMetadata httpGetEnabled</span><span class="pun">=</span><span class="str">"true"</span><span class="pln"> httpsGetEnabled</span><span class="pun">=</span><span class="str">"true"</span><span class="pun">/></span>
          <span class="pun"><!--</span> <span class="typ">To</span><span class="pln"> receive exception details </span><span class="kwd">in</span><span class="pln"> faults </span><span class="kwd">for</span><span class="pln"> debugging purposes</span><span class="pun">,</span> <span class="typ">set</span><span class="pln"> the value below to </span><span class="kwd">true</span><span class="pun">.</span>  <span class="typ">Set</span><span class="pln"> to </span><span class="kwd">false</span><span class="pln"> before deployment to avoid disclosing exception information </span><span class="pun">--></span>
          <span class="pun"><</span><span class="pln">serviceDebug includeExceptionDetailInFaults</span><span class="pun">=</span><span class="str">"false"</span><span class="pun">/></span>
        <span class="pun"></</span><span class="pln">behavior</span><span class="pun">></span>
      <span class="pun"></</span><span class="pln">serviceBehaviors</span><span class="pun">></span>
    <span class="pun"></</span><span class="pln">behaviors</span><span class="pun">></span>
    <span class="str"><protocolMapping></span>
      <span class="pun"><</span><span class="pln">add binding</span><span class="pun">=</span><span class="str">"basicHttpsBinding"</span><span class="pln"> scheme</span><span class="pun">=</span><span class="str">"https"</span> <span class="pun">/></span>
    <span class="pun"></</span><span class="pln">protocolMapping</span><span class="pun">></span>
    <span class="pun"><</span><span class="pln">serviceHostingEnvironment aspNetCompatibilityEnabled</span><span class="pun">=</span><span class="str">"true"</span><span class="pln"> multipleSiteBindingsEnabled</span><span class="pun">=</span><span class="str">"true"</span> <span class="pun">/></span>
  <span class="pun"></</span><span class="pln">system</span><span class="pun">.</span><span class="pln">serviceModel</span><span class="pun">></span>
  <span class="pun"><</span><span class="pln">system</span><span class="pun">.</span><span class="pln">webServer</span><span class="pun">></span>
    <span class="pun"><</span><span class="pln">modules runAllManagedModulesForAllRequests</span><span class="pun">=</span><span class="str">"true"</span><span class="pun">/></span>
    <span class="pun"><!--</span>
        <span class="typ">To</span><span class="pln"> browse web app root directory during debugging</span><span class="pun">,</span> <span class="typ">set</span><span class="pln"> the value below to </span><span class="kwd">true</span><span class="pun">.</span>
        <span class="typ">Set</span><span class="pln"> to </span><span class="kwd">false</span><span class="pln"> before deployment to avoid disclosing web app folder information</span><span class="pun">.</span>
      <span class="pun">--></span>
    <span class="pun"><</span><span class="pln">directoryBrowse enabled</span><span class="pun">=</span><span class="str">"true"</span><span class="pun">/></span>
  <span class="pun"></</span><span class="pln">system</span><span class="pun">.</span><span class="pln">webServer</span><span class="pun">></span>
<span class="pun"></</span><span class="pln">configuration</span><span class="pun">>
shareedit

Amr,

This sounds like you may have permission issues in the folder you .svc is running from, please can you check and see if the following permissions are there:

  • \IIS_IUSERS
  • \IIS_IUSR —If running webservice in Anonymous Mode

For the issue with protocol Mapping, please ensure that the app Pool you are using for the IIS site is setup to use .net 4, as from what I understand protocol mapping is only available in .net 4.

Hope this helps

shareedit
Advertisements

WCF Test Client Error: ‘IMetadataExchange’ not match

http://www.zizhujy.com/blog/post/2012/04/01/WCF-Test-Client-Error-IMetadataExchange-not-match.aspx

Problem:

When adding a service in your WCF Test Client, you meet this issue says:

The contract ‘IMetadataExchange’ in client configuration does not match the name in service contract, or there is no valid method in this contract.
To recover, please manually correct client configuration.
Or restore to default configuration.
Or check "Always regenerate config when launching services" in the
Tools -> Options menu, then refresh the service.

The screen shot:

WCF Test Client Error: ‘IMetadataExchange’ not match

After you click “OK”, the service node will appear in the tree with the redundant “IMetadataExchange (sb)”, “IMetadataExchange (sap)”, … sections.

WCF Test Client Error: ‘IMetadataExchange’ not match

Cause:

Caused by BizTalk according to http://blogs.msdn.com/b/wcftoolsteamblog/archive/2008/08/28/tips-for-wcf-tools-in-vs2008-sp1.aspx.

Solution:

When you run the WCF Test Client, modify the machine.config file (located in C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config)

machine.config

by commenting out the <client /> section below that is nested in the <system.serviceModel> element.

  &lt;!--
        &lt;client&gt;
            &lt;endpoint address="" binding="netTcpRelayBinding" contract="IMetadataExchange" name="sb"/&gt;
            &lt;endpoint binding="sapBinding" contract="IMetadataExchange" name="sap"/&gt;
            &lt;endpoint binding="siebelBinding" contract="IMetadataExchange" name="siebel"/&gt;
            &lt;endpoint binding="sqlBinding" contract="IMetadataExchange" name="mssql"/&gt;
            &lt;endpoint binding="oracleEBSBinding" contract="IMetadataExchange" name="oracleebs"/&gt;
            &lt;endpoint binding="oracleDBBinding" contract="IMetadataExchange" name="oracledb"/&gt;
            &lt;metadata&gt;
                &lt;policyImporters&gt;
                    &lt;extension type="System.ServiceModel.Channels.ContextBindingElementImporter, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.TcpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.HttpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.OnewayRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                &lt;/policyImporters&gt;
                &lt;wsdlImporters&gt;
                    &lt;extension type="System.ServiceModel.Channels.ContextBindingElementImporter, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.StandardRelayBindingImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.TcpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.HttpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                    &lt;extension type="Microsoft.ServiceBus.Description.OnewayRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
                &lt;/wsdlImporters&gt;
            &lt;/metadata&gt;
        &lt;/client&gt;
  --&gt;
After that, restart your WCF Test Client you will get rid of this error.