WCF: how to do "Add service link" to SSL service (I get errors)

FooService.svc.cs:

[ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
public interface IFooBar
{
    [OperationContract()]
    int Add(int num1, int num2);
}

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class FooService : IFooBar
{
    public int Add(int num1, int num2)
    {
        return num1 + num2;
    }
}

Web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <system.web>
    <customErrors mode="Off"/>
    <globalization culture="en-US" uiCulture="en-US" />
    <compilation defaultLanguage="c#" targetFramework="4.0" />
  </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <defaultDocument>
            <files>
                <add value="index.aspx" />
            </files>
        </defaultDocument>
  </system.webServer>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener" />
        </listeners>
      </source>

      <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener" />
        </listeners>
      </source>
      <source name="System.Runtime.Serialization" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="ServiceModelTraceListener" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="App_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
    </sharedListeners>
  </system.diagnostics>

</configuration>

I published the files on my server (which has the ssl certificate), but when I go to the webpage: https: // localhost: 443 / FooService.svc I get the following error ...

The request message must be protected. This is required by the operation contract ('IFooBar', 'HTTP://tempuri.org/'). protection must be provided by binding ('BasicHttpBinding', 'HTTP://tempuri.org/').

This happens if I go directly to the URL, or if I go to Add Service Reference...from Visual Studio.


Also, if I change [ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]to [ServiceContract], it works great.

+3
1

HTTP WCF 4 basicHttpBinding. , . basicHttpBinding , wsHttpBinding :

<system.serviceModel>
   <protocolMapping>
      <remove scheme="http" />
      <add scheme="http" binding="wsHttpBinding" bindingConfiguration="" />
   </protocolMapping>
... snip ...
</system.serviceModel>
+4

All Articles