I generated classes in JavaScript from a WSDL by using Visual Studio's WSDL utility.
wsdl /o:SomeClasses.js /l:js https://SomeCompany.com/SomeService?WSDL
The output contains classes (in JavaScript) that look like this:
public System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1") System.SerializableAttribute() System.Diagnostics.DebuggerStepThroughAttribute() System.ComponentModel.DesignerCategoryAttribute("code") System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:some.company")
class SomeUser {
private var domainNameField : System.String;
private var userNameField : System.String;
///<remarks/>
public final function get domainName() : System.String {
return this.domainNameField;
}
public final function set domainName(value : System.String) {
this.domainNameField = value;
}
///<remarks/>
public final function get userName() : System.String {
return this.userNameField;
}
public final function set userName(value : System.String) {
this.userNameField = value;
}
}
Is it possible to write OOP JavaScript utilizing these classes? If so, what is the syntax, examples, etc.
When you specify the JS language for the Web Services Description Language Tool, you are NOT specifying JavaScript, but JScript. It's not even JScript that InternetExplorer can fully understand, it's JScript.NET.
JScript.NET is a server side scripting language based on JScript but with added features - available only on the server side - like the class you've got in the code you posted.
You should look for other ways of generating JavaScript code, maybe with a tool like Wsdl2js or performing your WS call with JQuery. You can't use the Wsdl.exe generated code inside InternetExplorer as InternetExplorer only supports the old JScript language (and non IE browsers don't even support that).
Related
I have a requirement to develop a tool to backup certain folders and files present in a shared drive (Windows 7) using Client-Side technologies (HTML5, CSS3 and JavaScript) only. Below is the JavaScript function to copy the file.
function copyFile() {
var myObject, f;
myObject = new ActiveXObject("Scripting.FileSystemObject");
f = myObject.GetFile("#\\Network_Name\Home$\User_Folder\Downloads\Folder_Name\Test.pdf");
if(!f)
{
return alert("File Not Found");
}
f.copy("#\\Network_Name\Home$\User_Folder\Downloads\Backup_Folder");
}
Since I'm using ActiveXObject, the above code will work only in IE. But I'm getting the below error in the line #\\Network_Name\Home$\User_Folder\Downloads\Folder_Name\Test.pdf. Please help me to properly access the network folder using JavaScript.
The verbatim identifier (#) is for C# not JavaScript, you need to escape your slashes:
.GetFile("\\\\Network_Name\\Home$\\User_Folder\\Downloads\\Folder_Name\\Test.pdf");
Try to use Ajax request method type "GET" for this purpose.
I try to convert sample .net application with P/Invoke to javascript with JSIL.
C# code:
[DllImport("JSTestLib", EntryPoint = "Get42", CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int Get42();
Generated javascript:
$.ExternalMethod({Static:true , Public:true }, "Get42",
JSIL.MethodSignature.Return($.Int32)
);
Where should I add implementation of the Get42 method in javascript? Should I register this method manually in JSIL?
I have only an error now:
The external method 'System.Int32 Get42()' of type 'Test.Program' has
not been implemented.
Just use JSIL.ImplementExternals - take a look at JSIL.Core.js for examples
I have a wicket application in which I have added the javascript files within the markup html:
<script src="script/jquery.min.js" type="text/javascript"></script>
My javascript files are not placed beside my .java or .html files, they are in different location in the server as can be seen on previous script declaration.
My question is: Is it possible to add these javascript files depending on the application mode? I.E. if the application is in development mode, load one javascript file, if it is in production load this other one.
Thanks!
PS: the idea is to load "min" version on production but the extended files on development so debugging becomes posible
NOTE: Watching different answers here I re-state: the problem is not finding when the wicket app is in development or deployment mode, I know that, but is about how to change html markup or adding different JavaScript resources
extendig the answer of #rotsch you can do it in wicket 1.5 with :
#Override
public void renderHead(IHeaderResponse response) {
if(DEVELOPMENT)
response.renderString("<script type=\"text/javascript\" src=\"url1\"></script>");
else
response.renderString("<script type=\"text/javascript\" src=\"url2\"></script>");
}
https://cwiki.apache.org/WICKET/migration-to-wicket-15.html#MigrationtoWicket1.5-RemovedHeaderContributorandfriends.
You can find out in which mode you are with the following code:
RuntimeConfigurationType.DEPLOYMENT.equals(getApplication().getConfigurationType())
or
RuntimeConfigurationType.DEVELOPMENT.equals(getApplication().getConfigurationType())
I use this directory layout:
resources
|---JQueryResource.java
|---jquery-1.6.4.js
|---jquery-1.6.4.min.js
With this class:
public class JQueryResource {
/**
* Must be called in a RequestCycle.
*
* #return Url for the jQuery library.
*/
public static String getURL() {
if (Application.get().usesDevelopmentConfig()) {
Url url =
RequestCycle.get().mapUrlFor(
new PackageResourceReference(JQueryResource.class, "jquery-1.6.4.js"),
null);
return url.toString();
} else {
Url url =
RequestCycle.get().mapUrlFor(
new PackageResourceReference(JQueryResource.class,
"jquery-1.6.4.min.js"), null);
return url.toString();
}
}
}
This is how I add the resource to my page.
#Override
public void renderHead(IHeaderResponse a_response) {
a_response.renderJavaScriptReference(JQueryResource.getURL());
}
You could use pack:tag to compress all your resources: http://sourceforge.net/projects/packtag/
In your web.xml/.properties file you can specify whether to pack it or not depending on your production mode.
I set a property in a properties file with I add to the path when starting the VM.
Then I do a if else similar to the PHP answer.
I need to export my EditorGridPanel grid data to excel without sending any data to server-side, cross browser and cross platform solution that will work in ie6 and ie7. Any pure JavaScript solution is good as well!
So far i have found only data URI solution which is great but ie supports it only from 8-th version. Also there is a possibility to export through ActiveX component but it is not what i want since it makes my app depended to Windows and MSOffice.
Can you recommend me any solution ?
You could export to csv and then import that file into Excel , Open Office or Numbers?
Well after a wile of thinking i understood that this question is stupid because due to sandbox policy of js there is no possibility to export it directly from js.
As i said earlier i found some partial ways to do that:
ActiveX export and Data URI scheme
Here is a solution with a server-side call, but no server-side code writting.
http://code.google.com/p/gwt-table-to-excel/
The class below do that without server side.
public class TableToExcel {
public static final <T> void save(final CellTable<T> table, String filename) {
final AnchorElement a = Document.get().createAnchorElement();
a.setHref("data:application/vnd.ms-excel;base64," + base64(table.getElement().getString()));
a.setPropertyString("download", (filename.endsWith(".xls") || filename.endsWith(".xlsx")) ? filename : filename + ".xls");
Document.get().getBody().appendChild(a);
Scheduler.get().scheduleEntry(new ScheduledCommand() {
#Override
public void execute() {
click(a);
a.removeFromParent();
}
});
}
private static native void click(Element elem) /*-{
elem.click();
}-*/;
public static native String base64(String data) /*-{
return btoa(data);
}-*/;
}
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
force browsers to get latest js and css files in asp.net application
I'm working with someone else's code, so I don't know the whole picture, and I don't even know MVC that well, but here's the problem...
In Site.Master there's a
<%= Html.IncludeJs("ProductPartial")%>
which produces this line in the final mark-up
<script type="text/javascript" src="/Scripts/release/ProductPartial.js"></script>
I made some changes in the JS file, but the old one is obviously cached by the browser, so the changes won't show up until the user refreshes. The usual workaround is to add a version tag at the end of the script source path, but I'm not sure how to do that in this case.
Any suggestions?
Why not write your own Html helper extension method, and make it output the version number of your application assembly? Something along these lines should do the trick:
public static MvcHtmlString IncludeVersionedJs(this HtmlHelper helper, string filename)
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
return MvcHtmlString.Create(filename + "?v=" + version);
}
You can then increment the version number of the assembly whenever you release a new version to your users, and their caches will be invalidated across the application.
I solved this by tacking a last modified timestamp as a query parameter to the scripts.
I did this with an extension method, and using it in my CSHTML files. Note: this implementation caches the timestamp for 1 minute so we don't thrash the disk quite so much.
Here is the extension method:
public static class JavascriptExtension {
public static MvcHtmlString IncludeVersionedJs(this HtmlHelper helper, string filename) {
string version = GetVersion(helper, filename);
return MvcHtmlString.Create("<script type='text/javascript' src='" + filename + version + "'></script>");
}
private static string GetVersion(this HtmlHelper helper, string filename)
{
var context = helper.ViewContext.RequestContext.HttpContext;
if (context.Cache[filename] == null) {
var physicalPath = context.Server.MapPath(filename);
var version = "?v=" +
new System.IO.FileInfo(physicalPath).LastWriteTime
.ToString("yyyyMMddhhmmss");
context.Cache.Add(physicalPath, version, null,
DateTime.Now.AddMinutes(1), TimeSpan.Zero,
CacheItemPriority.Normal, null);
context.Cache[physicalPath] = version;
return version;
}
else {
return context.Cache[filename] as string;
}
}
And then in the CSHTML page:
#Html.IncludeVersionedJs("/MyJavascriptFile.js")
In the rendered HTML, this appears as:
<script type='text/javascript' src='/MyJavascriptFile.ks?20111129120000'></script>
Here are some links already on this topic:
Why do some websites access specific versions of a CSS or JavaScript file using GET parameters?
force browsers to get latest js and css files in asp.net application
Your version strategy really isn't important. As long as the file name is different, the browser will be forced to get the new script. So even this would work:
<%= Html.IncludeJs("ProductPartialv1")%>
ProductPartialv1.js
I have been using this technique for important JavaScript and CSS changes (CSS is also cached by the browser) - so I update the template to use the newer version and I'm safe in the knowledge that if the new HTML is used, so is the new script and CSS file.
It is "in action" on http://www.the-mag.me.uk/ - where I just increment a numeric suffix on the files.
It turns out IncludeJs is a helper method for automatically including compressed JS files when in release mode: LINK.
So I just have to modify that method a bit to include a version number. Sorry about the confusion.