Created
July 31, 2013 15:59
-
-
Save awrowse/6123336 to your computer and use it in GitHub Desktop.
WCF with WSSE Header with Nonce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment