Skip to content

Instantly share code, notes, and snippets.

@JoanComasFdz
JoanComasFdz / gist:1527190
Created December 28, 2011 09:02
Basic netTcpBinding with message-based security using username and password
<bindings>
<netTcpBinding>
<binding name="tcp_auth"
portSharingEnabled="false">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
@JoanComasFdz
JoanComasFdz / gist:1527196
Created December 28, 2011 09:04
Basic service behaviour with username and password authentication
<behaviors>
<serviceBehaviors>
<behavior name ="beh_auth">
<serviceMetadata/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="YOUR_HOST_NAMESPACE.YOUR_CUSTOM_VALIDATOR, YOUR_ASSEMBLY_NAME"/>
<serviceCertificate
findValue="YOUR_CERT_NAME"
@JoanComasFdz
JoanComasFdz / gist:1527198
Created December 28, 2011 09:05
Basic binding for a WCF service client using username and password.
<client>
<endpoint address="YOUR_SERVICE_URL"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_YOUR_REFERENCED_SERVICE_INTERFACE"
contract="YOUR_REFERENCED_SERVICE.YOUR_REFERENCED_SERVICE_INTERFACE"
name="NetTcpBinding_YOUR_REFERENCED_SERVICE_INTERFACE">
<identity>
<dns value="dev_cert_2"/>
<certificate encodedValue="..." />
</identity>
@JoanComasFdz
JoanComasFdz / gist:1527200
Created December 28, 2011 09:05
Basic console program to acces a WCF service via using username and password.
static void Main(string[] args)
{
Service1Client client = null;
try
{
// Create the client
// It will use the settings in the app.config file
client = new Service1Client();
// Set credentials
client.ClientCredentials.UserName.UserName = "USER_PASSWORD";
@JoanComasFdz
JoanComasFdz / MyNotImplementableStringEnum.cs
Created December 28, 2011 09:13
Not-implementable string enum
public enum MyStringEnum
{
Text1 = "My text 1",
}
@JoanComasFdz
JoanComasFdz / StringValueAttribute.cs
Created December 28, 2011 09:13
Attribute to contain a string value
/// <summary>
/// This attribute allows to attach to any
/// class, method, property or enumerator member
/// a string value.
/// </summary>
public class StringValueAttribute : Attribute
{
/// <summary>
/// Returns the attached string value.
/// </summary>
@JoanComasFdz
JoanComasFdz / StringEnum.cs
Created December 28, 2011 09:14
A class that uses generics to parse and get a value from an enumerator member with a StringValueAttribute.
/// <summary>
/// Provides the tools needed to get in a easy, fast way
/// the string value of an enumerator member assigned
/// with <see cref="StringValueAttribute"/>.
/// </summary>
/// <typeparam name="E">The type of the enumerator.</typeparam>
public static class StringEnum<E>
{
/// <summary>
/// Gets the enumerator member's string value.
@JoanComasFdz
JoanComasFdz / MyStringEnum.cs
Created December 28, 2011 09:14
An enumerator example type with string values.
/// <summary>
/// This is an example of how to implement
/// an string enum.
/// </summary>
public enum MyStringEnum
{
[StringValue("This is the string value 1.")]
Member1,
[StringValue("This is the string value 1.")]
Member2,
@JoanComasFdz
JoanComasFdz / gist:1527253
Created December 28, 2011 09:15
Getting the string value of an string enumerator and parsing it again.
// Get the value from the first member of the enumerator.
string value = StringEnum<MyStringEnum>.Value(MyStringEnum.Member1);
// Parse the value to re-obtain the member.
MyStringEnum member = StringEnum<MyStringEnum>.Parse(value);
@JoanComasFdz
JoanComasFdz / WinFormsFlashControl.cs
Created December 28, 2011 10:19
Basic WinForms control to contain a SWF Flash object.
partial class WinFormsFlashControl :System.Windows.Forms.UserControl
{
private Uri _source;
/// <summary>
/// Gets or sets the path to the .swf file.
/// </summary>
/// <exception cref="FileNotFoundException">Occurs when
/// the specified file is not found.</exception>
public Uri Source