For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 2 replies, 2 voices, and was last updated 14 years, 4 months ago by
anjads.
-
AuthorPosts
-
anjadsMemberDear,
I developed a web service that it should return JSON data format as below in ASP.net, and I deployed this web Service into my local IIS as below. Then i am trying to call the webservice from a javascript in the custom javascript file but it gives me error, please how can i call an ASP.net web service from MobiOne.
Below are the service code and the Javascript that I wrote in MobiOne custom java script file
—————————————-
Web Service Code
—————————————-Imports System
Imports System.Web
Imports System.Collections
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
Imports System.ComponentModel<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:=”http://localhost/”)> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WSRes
Inherits System.Web.Services.WebService<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function getConfigurationValueByKey() As StringDim strConn As String = My.Settings.strConn
Dim sqlConnection As SqlConnection = New SqlConnection(strConn)
sqlConnection.Open()
Dim sqlCommand As SqlCommand = New SqlCommand(“SELECT * FROM tblRes WHERE [Country] ='” + “KW” + “‘;”, sqlConnection)
Dim sqlDataset As DataSet = New DataSet()
Dim sqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(sqlCommand)
sqlDataAdapter.Fill(sqlDataset)
sqlConnection.Close()Dim MArray()() As String = New String(sqlDataset.Tables(0).Rows.Count)() {}
Dim i As Integer = 0
For Each rs As DataRow In sqlDataset.Tables(0).Rows
MArray(i) = New String() {rs(“Country”).ToString(), rs(“ResName”).ToString()}
i = i + 1
Next
Dim js As JavaScriptSerializer = New JavaScriptSerializer()
Dim sJSON As String = js.Serialize(MArray)
Return sJSON
End Function
End Class—————
JavaScript
—————
function AddRest() {var theDropDown = document.getElementById(“m1-MainPageRes-hidden-select-combobox2”);
$.ajax({ type: “POST”,
url: “http://localhost/WSRes.asmx/getConfigurationValueByKey”,
contentType: “application/json; charset=utf-8”,
data: “{}”,
dataType: “json”,
success: function(response) {
alert(response);},
error: function(req, status, error) {
alert(error);
alert(req);
alert(status);
}
});var thedrop =document.getElementById(“m1-MainPageRes-combobox2”);
var optn = document.createElement(“OPTION”);
optn.text = “Haha”;
optn.value = “Haha”;
theDropDown.options.add(optn);
theDropDown.options.selectedIndex = 0;
thedrop.innerText = optn.text;}
The Error I Am Getting Not Known as below
See attachment Error.pngAttachments:
You must be logged in to view attached files.April 9, 2012 at 8:29 am #325060
support-michaelKeymasterSome tips:
1) Turn off the local web server (Window>Settings>Local Web Server). Then run your mail UI in the test center or load it from file system, url = file://... By running from file:// you should not experience any same origin issues
2) In Test Center open Tool Panel and Debug into your code. Set a breakpoint an step. Many times you can find your problem watching the execution.
April 9, 2012 at 2:07 pm #325074
anjadsMemberThank you for your reply, I did what you sent and it worked perfect,
-
AuthorPosts
