<html>
<head>
<script>
function Say() {
//private
var nameA = "ha";
//public
this.nameB = "he";
//private
function sayBye() {
return "Bye!" + nameA;
}
//Privileged -> cannot be shared by all instances
this.sayHello = function() {
return "Hello!" + nameA;
}
}
//static
Say.nameC = "wa";
//static
Say.sayBye = function() {
return "Bye!" + this.nameC;
}
//public -> can be shared by all instances
Say.prototype.sayHi = function() {
return "Hi!" + this.nameB;
}
var a = new Say();
a.sayWa = function ()
{
return "Wa!" + a.nameB;
}
alert(a.sayHello());
alert(a.sayHi());
alert(Say.sayBye());
alert(a.sayWa());
var b = new Say();
alert(b.sayHi());
alert(b.sayWa()); //throw exception
</script>
</head>
<body>
</body>
</html>
SuperMan
A place for sharing
Thursday, February 11, 2016
Friday, June 13, 2014
Get all value from Divs using Jquery
I would like to get all values under a div list into an array.
var list = new Array();
$('.className').each(function() {list.push(this.value);});
Tuesday, January 28, 2014
SSRS: System.Security.Permissions.SecurityPermission
I install the assembly in GAC and reference the dll in a report template. When I use a custom dll to generate barcode in SSRS, an error message is shown.
"Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
I know that it's something about the permission issue. But I don't have any idea on it. After that, I find out that the configuration of reporting server and report designer are two different thing. And my target is reporting server only.
(1). Register dll in GAC
(2). Grant full trust in rssrvpolicy.config
<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="ThisDataProviderCodeGroup" Description="Code group for the .NET data provider"> <IMembershipCondition class="UrlMembershipCondition" version="1" Url= "C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin\DataProviderAssembly.dll" /> </CodeGroup>
After restarting the reporting services, I upload the report to my reporting server and the report works well.
Monday, November 25, 2013
Configuration of Class Library
I have developed a ws client in a class library and the code of the ws client is generated by adding a web references. When I want to move the ws client from uat environment to production environment, the client does not work at all. The problem is raised since I only update the configuration of app.config inside the class library. As the ws client is a class library, the configuration in app.config will be ignored. Afterwards, I update the Reference.cs which is generated by vs.
.Net: This application needs to use a cryptographic key
My application is required to integrated with a HTTPS web services. A popup windows is shown when I execute the console application under debug mode. It requests some permission for key access. After I grant the access, the application works fine.
Then, I publish the application to IIS and windows security popup is shown when I browse the site. Actually, the site doesn't work.
The absence of windows security popup gives me some idea on the permission on existing private key.
There are two ways to solve above issue.
1. Give permission to this folder C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys directly
2. Go to cmd-> type "mmc"-> add snapin certificate->click folder personal->right click->All Tasks->import your private key->right click your private key->All Tasks->Manage Private Key...->grant the permission.
Friday, September 27, 2013
Soap WS-Security Header : One of "SOAP Header" elements required
I run a C# web service client to connect to a Java web service. Then, it throws a exception: [com.ibm.wsspi.wssecurity.SoapSecurityException:WSEC5048EL One of "SOAP Header" elements required]. As no header is defined in the wsdl, I have no idea about the exception and don't know what should be added to the header. Further, the generated web service client does not have a header property. That means, I cannot add the header to the client directly.
After searching, I found out that WS-Security is a standard.
Then, I try to find out where I can insert the header to the requested XML. Below it's a one of the solutions that I found out on ASP.NET forum.
WSHeader .cs
public class WSHeader : SoapExtension
{
public bool outgoing = true;
public bool incoming = false;
private Stream outputStream;
public Stream oldStream;
public Stream newStream;
// The ChainStream, GetInitializers, Initialize, and ProcessMessage are required
// for a Soap override. ChainStream and ProcessMessage are what we need.
/// <summary>
/// Override. Save old stream, create new one.
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
public override Stream ChainStream(Stream stream)
{
// save a copy of the stream, create a new one for manipulating.
this.outputStream = stream;
oldStream = stream;
newStream = new MemoryStream();
return newStream;
}
#region "overrides of no interest"
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
throw new Exception("The method or operation is not implemented.");
}
public override object GetInitializer(Type serviceType)
{
return null;
}
public override void Initialize(object initializer)
{
return;
}
#endregion
/// <summary>
/// Return a string version of the XML
/// </summary>
/// <returns></returns>
public string getXMLFromCache()
{
newStream.Position = 0; // start at the beginning!
string strSOAPresponse = ExtractFromStream(newStream);
return strSOAPresponse;
}
/// <summary>
/// Transfer the text from the target stream from the
/// current position.
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
private String ExtractFromStream(Stream target)
{
if (target != null)
return (new StreamReader(target)).ReadToEnd();
return "";
}
/// <summary>
/// Override. Process .AfterSerialize and .BeforeDeserialize
/// to insert a non-standard SOAP header with username and
/// password (currently hard-coded).
/// </summary>
/// <param name="message"></param>
public override void ProcessMessage(SoapMessage message)
{
StreamReader readStr;
StreamWriter writeStr;
string soapMsg1;
XmlDocument xDoc = new XmlDocument();
// a SOAP message has 4 stages. We're interested in .AfterSerialize
switch (message.Stage)
{
case SoapMessageStage.BeforeSerialize:
break;
case SoapMessageStage.AfterSerialize:
{
// Get the SOAP body as a string, so we can manipulate...
String soapBodyString = getXMLFromCache();
// Strip off the old header stuff before the message body
// I'm not completely sure, but the soap:encodingStyle might be
// unique to the WebSphere environment. Dunno.
String BodString = "<soap:Body>";
int pos1 = soapBodyString.IndexOf(BodString) + BodString.Length;
int pos2 = soapBodyString.Length - pos1;
soapBodyString = soapBodyString.Substring(pos1, pos2);
soapBodyString = "<soap:Body>" + soapBodyString;
// Create the SOAP Message
// It's comprised of a <soap:Element> that's enclosed in <soap:Body>.
// Pack the XML document inside the <soap:Body> element
//String xmlVersionString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
String soapEnvelopeBeginString = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"http://tempuri.org/\" xmlns:types=\"http://tempuri.org/encodedTypes\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
String soapEnvHeaderString = "<soap:Header><Security><UsernameToken><Username>";
String soapEnvHeaderString2 = "</Username><Password>";
String soapEnvHeaderString3 = "</Password></UsernameToken></Security></soap:Header>";
Stream appOutputStream = new MemoryStream();
StreamWriter soapMessageWriter = new StreamWriter(appOutputStream);
//soapMessageWriter.Write(xmlVersionString);
soapMessageWriter.Write(soapEnvelopeBeginString);
//// The heavy-handed part - forcing the right headers AND the uname/pw :)
soapMessageWriter.Write(soapEnvHeaderString);
soapMessageWriter.Write(ConfigurationManager.AppSettings["WSUserName"]);
soapMessageWriter.Write(soapEnvHeaderString2);
soapMessageWriter.Write(ConfigurationManager.AppSettings["WSPassword"]);
soapMessageWriter.Write(soapEnvHeaderString3);
// End clubbing of baby seals
// Add the soapBodyString back in - it's got all the closing XML we need.
//soapBodyString = dammit;
soapMessageWriter.Write(soapBodyString);
// write it all out.
soapMessageWriter.Flush();
appOutputStream.Flush();
appOutputStream.Position = 0;
StreamReader reader = new StreamReader(appOutputStream);
StreamWriter writer = new StreamWriter(this.outputStream);
writer.Write(reader.ReadToEnd());
writer.Flush();
appOutputStream.Close();
this.outgoing = false;
this.incoming = true;
break;
}
case SoapMessageStage.BeforeDeserialize:
{
//Make the output available for the client to parse...
readStr = new StreamReader(oldStream);
writeStr = new StreamWriter(newStream);
soapMsg1 = readStr.ReadToEnd();
xDoc.LoadXml(soapMsg1);
soapMsg1 = xDoc.InnerXml;
writeStr.Write(soapMsg1);
writeStr.Flush();
newStream.Position = 0;
break;
}
case SoapMessageStage.AfterDeserialize:
break;
default:
throw new Exception("invalid stage!");
}
}
}
Add following to web.config
<system.web>
<webServices>
<soapExtensionTypes>
<add type="TDCWS.WSHeader,TDCWS" priority="1" group="Low"/>
</soapExtensionTypes>
</webServices>
</system.web>
Hope that can help!
References:
Monday, August 12, 2013
TFS: Access to the path is denied
I want to download latest version from TFS 2012 to test the project is uploaded to source control successfully or not. When I run the project, an error is occurred.
After a while, I discover the file property of the project is read-only. Hence, access is denied.
Then, I just wonder why the project become read-only. It is because I haven't check out the project through TFS before the download. So, please remember to check out the project via TFS or just uncheck the read-only properties of the project.
Subscribe to:
Posts (Atom)