PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 1.00 average.

call Ms.com WS without WSE

 
 
casey chesnut
Guest
Posts: n/a
 
      16th Sep 2003
full framework if you dont want to install WSE.
or compact framework where it doesnt exist.
casey
----------------------------------------------------------------------------
------
//SecurityHeader.cs
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.Text;

/*
//outgoing SoapHeader will look something like this
<wsse:Security soap:mustUnderstand="1"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
<wsse:UsernameToken
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"
wsu:Id="SecurityToken-9cda5cb3-f5c6-4ddf-b9fa-30ff0bcc97f5">
<wsse:Username>PZh3EOz8/GWV+PQel2OaZtrNv2x3/dBk</wsse:Username>
<wsse:Password
Type="wsse:PasswordDigest">aDmrV1Ek7pHKnFGiuc/WLQJMoiY=</wsse:Password>
<wsse:Nonce>rXl+0wUmcdMNbeMFmqGDiw==</wsse:Nonce>
<wsu:Created>2003-07-23T19:51:24Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>

//add public member to the auto gen'd webReference proxy
public bNb.WebServices.SecurityHeader securityHeader;

//add to WebMethod that will be called on auto gen'd webReference proxy
[System.Web.Services.Protocols.SoapHeaderAttribute("securityHeader")]

//change client code to set UsernameToken info
webReference.securityHeader = new bNb.WebServices.SecurityHeader();
webReference.securityHeader.UsernameToken.SetUserPass(username, password,
PasswordOption.SendHashed);

//Guid and Sha1 wrapper classes are needed based on platform:
//FULL FRAMEWORK
//guid = System.Guid.NewGuid();
//System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new
// System.Security.Cryptography.SHA1CryptoServiceProvider();
//bHash = sha1.ComputeHash(buffer);
//COMPACT FRAMEWORK
//guid - http://smartdevices.microsoftdev.com...icles/507.aspx
//sha1 - http://www.learnmobile.net/MobileCli...torials/cfWSE/
*/

namespace bNb
{
[XmlRoot(Namespace=NsConstants.wsse, ElementName="Security")]
public class SecurityHeader : SoapHeader
{
public SecurityHeader()
{
this.MustUnderstand = true;
this.UsernameToken = new UsernameToken();
}

[XmlElement(Namespace=NsConstants.wsse)]
public UsernameToken UsernameToken;
}

public class UsernameToken
{
public UsernameToken() {}

public void SetUserPass(string username, string password, PasswordOption
passType)
{
this.Username = username;

System.Guid g = Guid.NewGuid();
this.Id = "SecurityToken-" + g.ToString("D");

if(passType == PasswordOption.SendNone)
{
this.Password = null;
}

this.Password = new Password();

if(passType == PasswordOption.SendPlainText)
{
this.Password.Type = "wsse:PasswordText";
this.Password.Text = password;
}

if(passType == PasswordOption.SendHashed)
{
this.Password.Type = "wsse:PasswordDigest";

DateTime dtCreated = DateTime.UtcNow;
this.Created = XmlConvert.ToString(dtCreated, "yyyy-MM-ddTHH:mm:ssZ");
byte [] baCreated = Encoding.UTF8.GetBytes(this.Created);

//TODO crypto strength random number generator
this.Nonce = new Nonce();
Random r = new Random(Environment.TickCount);
byte [] baNonce = new byte[20];
r.NextBytes(baNonce);
this.Nonce.Text = Convert.ToBase64String(baNonce, 0, baNonce.Length);

byte [] baPassword = Encoding.UTF8.GetBytes(password);

int baDigestLength = baNonce.Length + baCreated.Length +
baPassword.Length;
byte [] baDigest = new byte[baDigestLength];
Array.Copy(baNonce, 0, baDigest, 0, baNonce.Length);
Array.Copy(baCreated, 0, baDigest, baNonce.Length, baCreated.Length);
Array.Copy(baPassword, 0, baDigest, baNonce.Length + baCreated.Length,
baPassword.Length);
byte [] hash = Sha1.ComputeHash(baDigest);

this.Password.Text = Convert.ToBase64String(hash, 0, hash.Length);
}
}

//required
[XmlElement(Namespace=NsConstants.wsse)]
public string Username;
[XmlAttribute(Namespace=NsConstants.wsu)]
public string Id;

//optional
[XmlElement(Namespace=NsConstants.wsse)]
public Password Password;
[XmlElement(Namespace=NsConstants.wsse)]
public Nonce Nonce;
[XmlElement(Namespace=NsConstants.wsu)]
public string Created;
}

public class Nonce
{
public Nonce(){}

[XmlText()]
public string Text;
//TODO handle hexEncode scenario
[XmlAttribute()]
public string EncodingType;
}

public class Password
{
public Password() {}

[XmlText()]
public string Text;
[XmlAttribute()]
public string Type;
}

public class NsConstants
{
public const string wsse = "http://schemas.xmlsoap.org/ws/2002/07/secext";
public const string wsu = "http://schemas.xmlsoap.org/ws/2002/07/utility";
}

public enum PasswordOption
{
SendHashed,
SendNone,
SendPlainText,
}

public enum EncodingType
{
Base64Binary,
HexBinary,
}
}


 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      17th Sep 2003
Very cool. Thank you!

"casey chesnut" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> full framework if you dont want to install WSE.
> or compact framework where it doesnt exist.
> casey



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a javascript when i call an aspx page with a form html not running on server Fabio Mastria Microsoft ASP .NET 4 28th Jan 2008 09:05 AM
Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that results in a call to a virtual method defined by the class. Review the following call stack for unintended consequences: steve bull Microsoft C# .NET 4 7th Jul 2005 05:54 PM
Are we new users supposed to call this number? I have auto dial on my XP in the dialer but am I required to call? Windows XP New Users 12 26th May 2005 03:47 PM
An outgoing call cannot be made since the application is dispatching an input-synchronous call Sagaert Johan Microsoft C# .NET 4 6th Apr 2005 12:12 AM
Re: Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Baavgai Microsoft C# .NET 0 4th Sep 2004 05:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:06 PM.