Skip to content

Instantly share code, notes, and snippets.

@awrowse
Created July 31, 2013 15:59

Revisions

  1. awrowse created this gist Jul 31, 2013.
    77 changes: 77 additions & 0 deletions wcf_wsse_nonce.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    using System.Windows.Forms;
    using System.ServiceModel;
    using NonceTest.OrgWS;
    using System.ServiceModel.Channels;
    using System.Xml;
    using Microsoft.Web.Services3.Security.Tokens;

    namespace NonceTest
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();

    EndpointAddress endPointAddr = new EndpointAddress("http://127.0.0.1:7777/v1/secure/OrganizationDetails");

    var binding = new BasicHttpBinding
    {
    Security =
    {
    Mode = BasicHttpSecurityMode.None,
    Transport =
    {
    ClientCredentialType = HttpClientCredentialType.Basic
    }
    }
    };


    // Create client
    GetOrganizationDetailsEndPointImplClient client = new OrgWS.GetOrganizationDetailsEndPointImplClient(binding, endPointAddr);

    organizationSummary[] response = null;

    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
    {

    //Class pulled from some old shit
    UsernameToken token = new UsernameToken("MY_USERNAME", "MY_PASSWORD", PasswordOption.SendHashed);

    //Add HTTP Auth Header (if needed)
    //var messageProperty = new HttpRequestMessageProperty();
    //messageProperty.Headers.Add(HttpRequestHeader.Authorization, "FOOOOO");
    //OperationContext.Current.OutgoingMessageProperties.Add(System.ServiceModel.Channels.HttpRequestMessageProperty.Name, messageProperty);


    //Add Auth to SOAP Header
    MessageHeader header
    = MessageHeader.CreateHeader(
    "Security",
    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
    token.GetXml(new XmlDocument())
    );

    OperationContext.Current.OutgoingMessageHeaders.Add(header);


    //Build Request
    getOrganizationDetailsRequestDTO request = new getOrganizationDetailsRequestDTO()
    {
    agentId = 6,
    agentLogin = "john.smith",
    contactIds = new int[] { 1 }
    };


    //Send Request
    response = client.getOrganizationSummary(request);

    }


    }
    }

    }