Last active
August 29, 2015 14:12
-
-
Save nonnb/8d835fbdc624a76def0c to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/27723127 - Creating a JSON Object from a VB.Net 3.5 ASMX WebMethod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication7._Default" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title></title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
</div> | |
</form> | |
</body> | |
</html> | |
<script src="https://code.jquery.com/jquery-1.11.2.js"></script> | |
<script> | |
$( function() { | |
$.ajax({ | |
type: "POST", | |
url: "/WebService1.asmx/RenderJson", | |
contentType: "application/json; charset=utf-8", | |
dataType: "json", | |
success: function (message) { | |
alert(message.d[0].file_name); | |
} | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------------------------ | |
' <auto-generated> | |
' This code was generated by a tool. | |
' | |
' Changes to this file may cause incorrect behavior and will be lost if | |
' the code is regenerated. | |
' </auto-generated> | |
'------------------------------------------------------------------------------ | |
Option Strict On | |
Option Explicit On | |
Partial Public Class _Default | |
'''<summary> | |
'''form1 control. | |
'''</summary> | |
'''<remarks> | |
'''Auto-generated field. | |
'''To modify move field declaration from designer file to code-behind file. | |
'''</remarks> | |
Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class _Default | |
Inherits System.Web.UI.Page | |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration> | |
<configSections> | |
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> | |
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> | |
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> | |
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> | |
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> | |
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> | |
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> | |
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> | |
</sectionGroup> | |
</sectionGroup> | |
</sectionGroup> | |
</configSections> | |
<appSettings/> | |
<connectionStrings/> | |
<system.web> | |
<!-- | |
Visual Basic options: | |
Set strict="true" to disallow all data type conversions | |
where data loss can occur. | |
Set explicit="true" to force declaration of all variables. | |
--> | |
<compilation debug="true" strict="false" explicit="true"> | |
<assemblies> | |
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> | |
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> | |
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> | |
</assemblies> | |
</compilation> | |
<!-- | |
The <authentication> section enables configuration | |
of the security authentication mode used by | |
ASP.NET to identify an incoming user. | |
--> | |
<authentication mode="Windows"/> | |
<!-- | |
The <customErrors> section enables configuration | |
of what to do if/when an unhandled error occurs | |
during the execution of a request. Specifically, | |
it enables developers to configure html error pages | |
to be displayed in place of a error stack trace. | |
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> | |
<error statusCode="403" redirect="NoAccess.htm" /> | |
<error statusCode="404" redirect="FileNotFound.htm" /> | |
</customErrors> | |
--> | |
<pages> | |
<namespaces> | |
<clear/> | |
<add namespace="System"/> | |
<add namespace="System.Collections"/> | |
<add namespace="System.Collections.Generic"/> | |
<add namespace="System.Collections.Specialized"/> | |
<add namespace="System.Configuration"/> | |
<add namespace="System.Text"/> | |
<add namespace="System.Text.RegularExpressions"/> | |
<add namespace="System.Linq"/> | |
<add namespace="System.Xml.Linq"/> | |
<add namespace="System.Web"/> | |
<add namespace="System.Web.Caching"/> | |
<add namespace="System.Web.SessionState"/> | |
<add namespace="System.Web.Security"/> | |
<add namespace="System.Web.Profile"/> | |
<add namespace="System.Web.UI"/> | |
<add namespace="System.Web.UI.WebControls"/> | |
<add namespace="System.Web.UI.WebControls.WebParts"/> | |
<add namespace="System.Web.UI.HtmlControls"/> | |
</namespaces> | |
<controls> | |
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
</controls> | |
</pages> | |
<httpHandlers> | |
<remove verb="*" path="*.asmx"/> | |
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
</httpHandlers> | |
<httpModules> | |
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
</httpModules> | |
</system.web> | |
<!-- | |
The system.webServer section is required for running ASP.NET AJAX under Internet | |
Information Services 7.0. It is not necessary for previous version of IIS. | |
--> | |
<system.codedom> | |
<compilers> | |
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"> | |
<providerOption name="CompilerVersion" value="v3.5"/> | |
<providerOption name="OptionInfer" value="true"/> | |
<providerOption name="WarnAsError" value="false"/> | |
</compiler> | |
</compilers> | |
</system.codedom> | |
<system.webServer> | |
<validation validateIntegratedModeConfiguration="false"/> | |
<modules> | |
<remove name="ScriptModule"/> | |
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
</modules> | |
<handlers> | |
<remove name="WebServiceHandlerFactory-Integrated"/> | |
<remove name="ScriptHandlerFactory"/> | |
<remove name="ScriptHandlerFactoryAppServices"/> | |
<remove name="ScriptResource"/> | |
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> | |
</handlers> | |
</system.webServer> | |
<runtime> | |
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"> | |
<dependentAssembly> | |
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> | |
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> | |
</dependentAssembly> | |
<dependentAssembly> | |
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> | |
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> | |
</dependentAssembly> | |
</assemblyBinding> | |
</runtime> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |
<PropertyGroup> | |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |
<ProductVersion> | |
</ProductVersion> | |
<SchemaVersion> | |
</SchemaVersion> | |
<ProjectGuid>{970F2DB1-37F8-4443-A683-7C4FFCAACD90}</ProjectGuid> | |
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids> | |
<OutputType>Library</OutputType> | |
<RootNamespace>WebApplication7</RootNamespace> | |
<AssemblyName>WebApplication7</AssemblyName> | |
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | |
<MyType>Custom</MyType> | |
<UseIISExpress>true</UseIISExpress> | |
<IISExpressSSLPort /> | |
<IISExpressAnonymousAuthentication /> | |
<IISExpressWindowsAuthentication /> | |
<IISExpressUseClassicPipelineMode /> | |
<TargetFrameworkProfile /> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
<DebugSymbols>true</DebugSymbols> | |
<DebugType>full</DebugType> | |
<DefineDebug>true</DefineDebug> | |
<DefineTrace>true</DefineTrace> | |
<OutputPath>bin\</OutputPath> | |
<DocumentationFile>WebApplication7.xml</DocumentationFile> | |
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> | |
<Prefer32Bit>false</Prefer32Bit> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
<DebugType>pdbonly</DebugType> | |
<DefineDebug>false</DefineDebug> | |
<DefineTrace>true</DefineTrace> | |
<Optimize>true</Optimize> | |
<OutputPath>bin\</OutputPath> | |
<DocumentationFile>WebApplication7.xml</DocumentationFile> | |
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> | |
<Prefer32Bit>false</Prefer32Bit> | |
</PropertyGroup> | |
<ItemGroup> | |
<Reference Include="System" /> | |
<Reference Include="System.Data" /> | |
<Reference Include="System.Data.DataSetExtensions" /> | |
<Reference Include="System.Drawing" /> | |
<Reference Include="System.Web.DynamicData" /> | |
<Reference Include="System.Web.Entity" /> | |
<Reference Include="System.Web" /> | |
<Reference Include="System.Web.Extensions" /> | |
<Reference Include="System.Xml" /> | |
<Reference Include="System.Configuration" /> | |
<Reference Include="System.Web.Services" /> | |
<Reference Include="System.EnterpriseServices" /> | |
<Reference Include="System.Web.Mobile" /> | |
<Reference Include="System.Xml.Linq" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Import Include="Microsoft.VisualBasic" /> | |
<Import Include="System" /> | |
<Import Include="System.Collections" /> | |
<Import Include="System.Collections.Generic" /> | |
<Import Include="System.Data" /> | |
<Import Include="System.Linq" /> | |
<Import Include="System.Xml.Linq" /> | |
<Import Include="System.Diagnostics" /> | |
<Import Include="System.Collections.Specialized" /> | |
<Import Include="System.Configuration" /> | |
<Import Include="System.Text" /> | |
<Import Include="System.Text.RegularExpressions" /> | |
<Import Include="System.Web" /> | |
<Import Include="System.Web.Caching" /> | |
<Import Include="System.Web.SessionState" /> | |
<Import Include="System.Web.Security" /> | |
<Import Include="System.Web.Profile" /> | |
<Import Include="System.Web.UI" /> | |
<Import Include="System.Web.UI.WebControls" /> | |
<Import Include="System.Web.UI.WebControls.WebParts" /> | |
<Import Include="System.Web.UI.HtmlControls" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Content Include="Default.aspx" /> | |
<Content Include="Scripts\jquery-1.7.1.intellisense.js" /> | |
<Content Include="Scripts\jquery-1.7.1.js" /> | |
<Content Include="Scripts\jquery-1.7.1.min.js" /> | |
<Content Include="Web.config" /> | |
<Content Include="WebService1.asmx" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Compile Include="Default.aspx.vb"> | |
<SubType>ASPXCodeBehind</SubType> | |
<DependentUpon>Default.aspx</DependentUpon> | |
</Compile> | |
<Compile Include="Default.aspx.designer.vb"> | |
<DependentUpon>Default.aspx</DependentUpon> | |
</Compile> | |
<Compile Include="My Project\AssemblyInfo.vb" /> | |
<Compile Include="My Project\Application.Designer.vb"> | |
<AutoGen>True</AutoGen> | |
<DependentUpon>Application.myapp</DependentUpon> | |
</Compile> | |
<Compile Include="My Project\MyExtensions\MyWebExtension.vb"> | |
<VBMyExtensionTemplateID>Microsoft.VisualBasic.Web.MyExtension</VBMyExtensionTemplateID> | |
<VBMyExtensionTemplateVersion>1.0.0.0</VBMyExtensionTemplateVersion> | |
</Compile> | |
<Compile Include="My Project\Resources.Designer.vb"> | |
<AutoGen>True</AutoGen> | |
<DesignTime>True</DesignTime> | |
<DependentUpon>Resources.resx</DependentUpon> | |
</Compile> | |
<Compile Include="My Project\Settings.Designer.vb"> | |
<AutoGen>True</AutoGen> | |
<DependentUpon>Settings.settings</DependentUpon> | |
<DesignTimeSharedInput>True</DesignTimeSharedInput> | |
</Compile> | |
<Compile Include="WebService1.asmx.vb"> | |
<DependentUpon>WebService1.asmx</DependentUpon> | |
<SubType>Component</SubType> | |
</Compile> | |
</ItemGroup> | |
<ItemGroup> | |
<EmbeddedResource Include="My Project\Resources.resx"> | |
<Generator>VbMyResourcesResXFileCodeGenerator</Generator> | |
<LastGenOutput>Resources.Designer.vb</LastGenOutput> | |
<CustomToolNamespace>My.Resources</CustomToolNamespace> | |
<SubType>Designer</SubType> | |
</EmbeddedResource> | |
</ItemGroup> | |
<ItemGroup> | |
<None Include="My Project\Application.myapp"> | |
<Generator>MyApplicationCodeGenerator</Generator> | |
<LastGenOutput>Application.Designer.vb</LastGenOutput> | |
</None> | |
<None Include="My Project\Settings.settings"> | |
<Generator>SettingsSingleFileGenerator</Generator> | |
<CustomToolNamespace>My</CustomToolNamespace> | |
<LastGenOutput>Settings.Designer.vb</LastGenOutput> | |
</None> | |
<None Include="Web.Debug.config"> | |
<DependentUpon>Web.config</DependentUpon> | |
</None> | |
<None Include="Web.Release.config"> | |
<DependentUpon>Web.config</DependentUpon> | |
</None> | |
</ItemGroup> | |
<ItemGroup> | |
<Folder Include="App_Data\" /> | |
</ItemGroup> | |
<PropertyGroup> | |
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> | |
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | |
</PropertyGroup> | |
<PropertyGroup> | |
<OptionExplicit>On</OptionExplicit> | |
</PropertyGroup> | |
<PropertyGroup> | |
<OptionCompare>Binary</OptionCompare> | |
</PropertyGroup> | |
<PropertyGroup> | |
<OptionStrict>Off</OptionStrict> | |
</PropertyGroup> | |
<PropertyGroup> | |
<OptionInfer>On</OptionInfer> | |
</PropertyGroup> | |
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" /> | |
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> | |
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" /> | |
<ProjectExtensions> | |
<VisualStudio> | |
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> | |
<WebProjectProperties> | |
<UseIIS>True</UseIIS> | |
<AutoAssignPort>True</AutoAssignPort> | |
<DevelopmentServerPort>51858</DevelopmentServerPort> | |
<DevelopmentServerVPath>/</DevelopmentServerVPath> | |
<IISUrl>http://localhost:51858/</IISUrl> | |
<NTLMAuthentication>False</NTLMAuthentication> | |
<UseCustomServer>False</UseCustomServer> | |
<CustomServerUrl> | |
</CustomServerUrl> | |
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> | |
</WebProjectProperties> | |
</FlavorProperties> | |
</VisualStudio> | |
</ProjectExtensions> | |
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |
Other similar extension points exist, see Microsoft.Common.targets. | |
<Target Name="BeforeBuild"> | |
</Target> | |
<Target Name="AfterBuild"> | |
</Target> | |
--> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ WebService Language="vb" CodeBehind="WebService1.asmx.vb" Class="WebApplication7.WebService1" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Web.Services | |
Imports System.Web.Services.Protocols | |
Imports System.ComponentModel | |
Imports System.Web.Script.Serialization | |
Imports System.Web.Script.Services | |
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. | |
<System.Web.Script.Services.ScriptService()> _ | |
Public Class WebService1 | |
Inherits System.Web.Services.WebService | |
<System.Web.Services.WebMethod()> _ | |
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ | |
Public Function RenderJson() As Object | |
Dim theObjects() = { | |
New With { | |
.file_name = "test1.exe", | |
.url = "http://127.0.0.1/heartkey/files/test1.exe", | |
.path = "images\filename\\" | |
}, | |
New With { | |
.file_name = "test2.exe", | |
.url = "http://127.0.0.1/anotherUrl", | |
.path = "images\foo" | |
} | |
} | |
Return theObjects | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment