Search code examples
wcfwcf-bindingwcf-security

WCF authentication with username and password soap request


I would like to authenticate request on WCF service with username and password the received request soap header will be like that, what should I configure wcf service to check this username and password in database then.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:ns="http://schemas.datacontract.org/2004/07/">
    <soapenv:Header>
        <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:UsernameToken wsu:Id="UsernameToken-2">
            <wsse:Username></wsse:Username>
            <wsse:Password></wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <tem:RequestForCustomsExemption>
            <customsExemptionRequest>
                <BILL_NUMBER>12583603</BILL_NUMBER>
            </customsExemptionRequest>
        </tem:RequestForCustomsExemption>
    </soapenv:Body>
</soapenv:Envelope>

Solution

  • You would need to use a Custom UsernamePasswordValidator extension. This article should have all of the info you need: How to: Use a Custom User Name and Password Validator