Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am developing a wcf restful and soap service. I use WebGet attribute in service interface. I define binding="webHttpBinding" in configuration file. How do you security at restful WCF service?

My servicemodel node :
XML
<system.serviceModel>
    <services>

      <service name="TestService.LisansService" behaviorConfiguration="ServiceBehaviors" >
        <endpoint contract="TestService.ILisansService" binding="wsHttpBinding" />
        <endpoint address="json" binding="webHttpBinding" contract="TestService.ILisansService"  behaviorConfiguration="RestServiceBindingBehaviorJSON" bindingConfiguration="webHttpBindingJSON"></endpoint>
        <endpoint address="xml" binding="webHttpBinding" contract="TestService.ILisansService" behaviorConfiguration="RestServiceBindingBehaviorXML" bindingConfiguration="webHttpBindingXml"></endpoint>

      </service>

    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="RestServiceBindingBehaviorJSON">
          <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
        </behavior>
        <behavior name="RestServiceBindingBehaviorXML">
          <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Xml" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>


        <behavior name="ServiceBehaviors">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName"
                             storeLocation="LocalMachine" storeName="My" />
            <userNameAuthentication userNamePasswordValidationMode="Custom"
             customUserNamePasswordValidatorType="TestService.UserAuthentication, TestService" />
          </serviceCredentials>
        </behavior>
        
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <wsHttpBinding>
        <binding>
          <security mode="Message">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
      <webHttpBinding>

        <binding name="webHttpBindingXml"></binding>
        <binding name="webHttpBindingJSON">
          <security mode="Transport"></security>
        </binding>
      </webHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


Thanks.
Posted
Updated 18-Jun-14 1:39am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900