oXML = Server.CreateObject("Msxml2.DOMDocument.4.0")
oNode = oXML.createElement("CommonCustomerSearch")
can someone explain what the lines of code above are doing? i'm more interested in the first line as the method it is written in exits when it hits that line, so apparently the variable oXML isn't being set. i know that oXML is supposed to be set to some kind of COM object but can you explain the "Msxml2.DOMDocument.4.0" part a bit more? what is that, where is that, and what will it look like in .NET (this code is a classic asp)? i don't know what the second line of code above is either but the method never even reaches it so if you have any ideas about what that is doing would be great too. thanks
That is code using the old MSXML COM object. The XML namespace in .NET will do almost the exact same thing, using similar syntax. And bypass COM (a good thing). Convert these statements to use .Net's XML.
Msxml2.DOMDocument.4.0 is the COM object name.
If the createobject is existing the method, then something is probably wrong.
In .net you can say, like, Dim MyXMLDocument as New XML.XMLDocument, etc.
That classic ASP code is making use of the XML DOM library. The first line (if properly coded with the set keyword) creates an XML document in memory. The second line creates an XML node named CommonCustomerSearch.
.NET Framework 3.5+
If you want to move to .NET 3.5 or later, you could do the same thing with System.Linq.Xml
var xmlDoc = new XDocument(new XElement("CommonCustomerSearch"));
You can read the Getting Started Guide for LINQ to XML for more info.
.NET Framework 2.0
It sounds like you're limited to .NET 2.0, so you can use System.Xml to accomplish this in a less sexy way.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<CommonCustomerSearch/>");
The Msxml2.DOMDocument.4.0 is a COM object and the line is supposed to create an instance of the class. I donĀ“t know if this is all the code but you are required to use the Set keyword when initializing an instance of an object. So it should in fact be
Set oXML = Server.CreateObject("Msxml2.DOMDocument.4.0")
Set oNode = oXML.createElement("CommonCustomerSearch")
The Msxml class is an abstraction of an xml document.
Related
I'm trying to use Webservice component in my Flex 4 application.
I need to use this in Actioncript and not using MXML tags.
I'm able to invoke the WSDL operations successfully, but the resultFormat is Object by default.
How do I set it to e4x?
var lookupService:WebService = new WebService();
lookupService.wsdl =url;
lookupService.loadWSDL();
lookupService.doLookup.addEventListener(ResultEvent.RESULT, lookupResultHandler);
lookupService.doLookup.addEventListener(FaultEvent.FAULT, faultHandler);
lookupService.doLookup(lookupString);
I tried to set the format by
lookupService.resultFormat = "e4x";
But this is not working. The calls are not even going through when I do this.
Can you please provide your suggestions for implementing this using AS3?
If you take a look at the two web service classes, you'll realize that resultFormat is not a property on either of them. Resultset is a property on the operations array.
If that doesn't help, you'll have to quantify "not working." What isn't working? Are you getting compile errors? Are you getting runtime errors? IS the data not being returned? Is the data not be returned as XML?
You'll probably have to set this up in MXML and dissect the generated ActionScript to figure out the appropriate AS3 syntax.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/soap/WebService.html
I built a small chunk of code based around lambdas in a VB Windows form project earlier which works perfectly, but it gives me "expression expected" warnings (which block compiling... should probably be considered errors, no?) when I copy the code to an ASP.NET project. The only difference I can see is if I make a Windows form project vs a Web project... works in one, doesn't work in another.
Even something basic like this doesn't work:
delegate function stringify(byval x as object) as string
public sub test()
dim f as stringify = Function(x) x.ToString()
dim s as string = f(5)
end sub
Is there a way to get Lambdas to work in ASP.NET? Or is there a setting somewhere yanking my version of VB down a level or two (since they apparently only work in 9.0 or later, but I don't know how to tell which version I'm using)?
Edit: Bah! LinqBridge doesn't seem to work for me. I get the objects (Func(Of TResult)), but no lambda support. I suppose that's the death-knell to my hopes? Or is there something obvious I'm missing to use it (drag to bin, target in references, Imports System.Linq) ?
You can if you use LinqBridge
It is an implementation of Linq for the .Net 2.0
As they say
LINQBridge is a reimplementation of all the standard query operators in Framework 3.5's Enumerable class.
...
In fact LINQBridge lets you use nearly all of the features in C# 3.0 with Framework 2.0 including extension methods, lambda functions and query comprehensions. The only feature it does not support is compiling lambdas to expression trees (i.e., Expression).
I am trying to achieve this but this is not working. I am sure i am missing something, please help me where i am wrong. I hope this is achievable. We should able to pass a string from ASP Page (using vbscript) to c# dll ( have this dll stored in gac and i have already registered it using regasm utility).
Below is my code:
Function GetObj()
Set Obj = Server.CreateObject("namespace.classname")
Set inputStr = Nothing
inputStr = "myString"
Set GetObj = Obj.dotnetMethod(inputStr)
SET Obj = NOTHING
End Function
The problem that i am facing is that when i passs inputStr to the obj.dotnetMethod, it is not recognising the string that i am passing from the asp page and it doesn't return to me any result which it should.
Could be a unicode problem--.Net expects unicode strings. ASP, I believe, does not.
But if you aren't even sure the method is registered, well then you have to make sure that dll is COM visible. ASP is a world that doesn't know anything about managed code or .Net. You have to use COM. You know, old school regsvr32, or ASP won't find it.
I can guess at a couple of things the might be going wrong (your question really needs more detail)
Set GetObj = Obj.dotnetMethod(inputStr)
dotnetMethod returns a String, DateTime or a primitive type such Int32 in which case you should remove the Set keyword.
dotnetMethod is return an object that isn't ComVisible itself.
BTW,
Set inputStr = Nothing
inputStr = "myString"
Why set inputStr to Nothing and then assign a string to it??
How do I write the following code in classic ASP? I am using this code in an include file.
byte[] bytes = new byte[stream.Length]
Also it would be great if anyone can say how to create object for StreamWriter in classic ASP.
Set sw = Server.CreateObject("System.IO.StreamWriter(stream)")
I am not sure about the code inside quotes System.IO.StreamWriter(stream).
Classic ASP is just plain old VBScript. CreateObject creates a COM object using the classid/progid: CreateObject("ADODB.Connection") or CreateObject("Scripting.FileSystemObject").
Classic ASP can use COM objects that are actually .NET objects... but only if they have been built specifically supporting COM interop. Most of the internal .NET stuff was not built supporting COM interop.
See: http://msdn.microsoft.com/en-us/library/zsfww439.aspx
If you just need a stream object (not necesarily a .NET System.IO.Stream object) then I'd recommend ADODB.Stream.
Also not that in ASP/VBScript all variables are variants. This makes things like an array of bytes tricky. You can have an array of variants no big deal, and all the variants could be bytes... but you can't create an array that can only hold bytes. To make matters stranger... if a COM object returns a SAFEARRAY of bytes then ASP/VBScript is happy to use it.
I don't think there's a direct translation to StreamWriter. My classic ASP objects knowledge is limited, but IIRC the closest match would be FileSystemObject. As for the byte array:
Dim bytes(stream.Length-1) As Byte
Not sure what you want to do, but..
When I wanted to handle byte arrays from vbscript like a BLOB coming from a database I made a general VB6 COM object that could perform operations on the byte array.
http://www.di-mgt.com.au/bytearrays.html
I have one JSON that is coming in a string format. I need to store it in a key-pair value or something like that. I am using asp.net 2.0 and can not use 3rd party DLL like Newtonsoft.Json.dll. I guess last option will be to use regular expression.
Can anybody please help me in this?
If you go to http://www.json.org/ and look towards the bottom of the page there are dozens of json libraries most of them open source, I believe they list 8 for C#. If you can not reference one of these libraries, I think your best bet would be to find one with a permissive license and simply add the code to your project.
Another idea is to look at the diagrams, grammer, and syntax at http://www.json.org/ and just write your own parser, but regex is NOT the way to do it. If you dont know how to write a parser you could look at one of the open source json libraries or start with something less complicated like a good CSV parser, here is a paper that looks pretty good: http://www.boyet.com/Articles/CsvParser.html
It is possible to serialize JSON using JScript in C# into key/value pairs. You need to add a few references to your project. They're part of the .NET framework, you just need to add the references to your project. You'll need:
Microsoft.JSript
Microsoft.Vsa
First, the usings at the top of your class:
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
Then the Engine that will execute the script needs to be initialized somewhere in your 'Page' code-behind:
VsaEngine Engine = VsaEngine.CreateEngine();
Then you just create this method and call it by passing in your JSON object:
object EvalJScript(string JScript)
{
object result = null;
try
{
result = Microsoft.JScript.Eval.JScriptEvaluate(JScript, Engine);
}
catch (Exception ex)
{
return ex.Message;
}
return result;
}
The type of object returned (if JSON is passed in) is a 'JSObject'. You can access its values as key/value pairs. Read the MSDN documentation for more details on this object.
Here's an example of using the code:
string json = "({Name:\"Dan\",Occupation:\"Developer\"})";
JSObject o = EvalJScript(json) as JSObject;
string name = o["Name"] as string; // Value of 'name' will be 'Dan'
Could you use JScript.NET?
If so, should be easy enough with eval() - then just loop through the objects returned and translate into KeyValuePair's or whatever
You will need to use jscript.net as the code behind language, but other pages of your site should be fine to stay as c# if thats what you prefer.
As mentioned in previous comment, you will need to be aware of the security aspects and risks - only use eval if you trust the JSON you're parsing!