Webservice not working in visual studio 2010 - asp.net-mvc

I have created a webservice in Visual studio 2010.I have created a database with a table which contains commands and their description.My program is:
My class:-DataHelper.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DataHelper
/// </summary>
public class DataHelper
{
public static string GetData(string Command)
{
string Explanation = " ";
SqlConnection con = new SqlConnection(#"Data Source=CSS-L3-D008;Initial Catalog=works1;Integrated Security=true;");
SqlCommand cmd = new SqlCommand("Select Explanation from Data1 where Command= '" + Command.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Explanation = dr["Explanation"].ToString();
}
dr.Close();
con.Close();
return Explanation;
}
}
And Service1.asmx
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Private Property DataHelper As Object
<WebMethod()>
Public Function HelloWorld() As String
Return "Hello World"
End Function
<WebMethod()>
Public Function GetData(Command) As String
Return DataHelper.GetData(Command)
End Function
End Class
the problem is that wen i run it i am getting both webmethods HelloWorld and GetData but GetData is not working.When i click HelloWorld() i get invoke method and it runs properly.But when i click GetData() i get invoke button but then it shows
"The test form is only available for methods with primitive types as parameters."
Actually it should give a box where i can enter the command and the description should be returned from the sql server.Please help me.

Should that GetData method in the service declare the type of the Command parameter?:
<WebMethod()>
Public Function GetData(Command As String) As String
Return DataHelper.GetData(Command)
End Function

Related

SignalR on Azure sends message to SignalR client within a LAN

We have the following mixed-environment scenario (Azure and LAN):
Azure Web App calls a method in the Azure API (triggered by some user action in the web app).
This Azure API then establishes a SignalR HubContext connection .
The HubContext broadcasts a message.
The SignalR client (consuming the message) is a Windows Service installed on a machine on the LAN, behind the firewall.
Our client is complaining that the connection often breaks, and therefore several messages are missing on a daily basis.
Here is a test method in the Azure API, which attempts to broadcast a message:
using Microsoft.AspNet.SignalR;
using System;
using System.IO;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.Caching;
using System.Text;
using System.Web.Http;
using System.Xml;
...
namespace MyTestAPI.Controllers
[AllowCrossSiteJson]
[RoutePrefix("api/Test")]
public class HL7Controller : ApiController
[HttpGet]
[Route("TestSignalR")]
public IHttpActionResult TestSignalR()
{
string reportData = $"<TestReport>This is a test message generated on { DateTime.Now }.</TestReport>";
var hubContext = GlobalHost.ConnectionManager.GetHubContext<HL7Hub>();
hubContext.Clients.All.SendReportData(reportData);
return Ok(reportData);
}
...
}
And in the client's environment, there's a Win Service installed - it acts as the SignalR Client
And here's a snippet of our H..NotificationsService solution (vs2019, Framework 4.6.1)
using log4net.Ext.EventID;
using Microsoft.AspNet.SignalR.Client;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Net;
using System.ServiceProcess;
using System.Threading;
namespace H_NotificationSrv
{
public partial class H_NotificationService : ServiceBase
public async void StartListner()
{
try
{
var hubConnection = new HubConnection(hl7APIUrl);
hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;
var hubProxy = hubConnection.CreateHubProxy("MyTestHub");
hubProxy.On<string>("SendReportData", reportData =>
{
SendReportDataToSomeone(reportData);
});
await hubConnection.Start();
}
catch (Exception ex)
{
string errorMessage = ex.Message;
if (ex.InnerException != null)
errorMessage += " Inner Exception: " + ex.InnerException.Message;
applog.Error(errorMessage);
}
}
}
}

How to detect IIS events in windows event logs and detemine its application pool according to this code?

I try to make a listener on windows event logs, but I need to recognize IIS events in it and determine its application pool.
could I do that according to this code ??? by process id for example or any thing else.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.DirectoryServices;
using Microsoft.Web;
using Microsoft.Web.Administration;
namespace EventLogEnt
{
class Program
{
static AutoResetEvent signal;
static void Main(string[] args)
{
// create new log
signal = new AutoResetEvent(false);
EventLog myNewLog = new EventLog("Application", "TIS3", "Outlook");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
signal.WaitOne();
Console.ReadKey();
}
public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
{
Console.WriteLine(e.Entry.Message);
Console.WriteLine("the entry type: " + e.Entry.EntryType);
Console.WriteLine("---------------------------------------------");
signal.Set();
}
}
}

Geolocation dont work on a desktop emulator (uwp)

Hello im trying to make a view containing a map in a Universal Windows platform
i did the fellowing :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Geolocation;
namespace Project
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Geolocation : Page
{
public Geolocation()
{
this.InitializeComponent();
}
public async void GetCords()
{
Geolocator locator = new Geolocator();
Geoposition pos = await locator.GetGeopositionAsync();
await new Windows.UI.Popups.MessageDialog(pos.CivicAddress.City).ShowAsync();
}
}
}
but i got a blank page! what am I missing here?
If you want to add a MapControl in your page, you must:
Create a key for your map
xmlns:maps="using:Windows.UI.Xaml.Controls.Maps <maps:MapControl
<maps:MapControl x:Name="map" MapServiceToken="YOUR_TOKEN_HERE" />

ToJSON method not found - which namespace is required?

I want to log .net WEB API request-response to newly created file. So, I have implemented NLog mechanism in my project which works great. but still below code's .ToJSON() line doesn't get resolved. I can't figure out which namespace is required to use it. is there anything missing out?
I'm referring these two articles but still can't figure out.
1) http://www.codeproject.com/Articles/1028416/RESTful-Day-sharp-Request-logging-and-Exception-ha
2) http://www.strathweb.com/2012/06/using-nlog-to-provide-custom-tracing-for-your-asp-net-web-api/
.net namespaces
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Http.Tracing;
using System.Net.Http;
using System.Text;
if (level != TraceLevel.Off)
{
if (traceAction != null && traceAction.Target != null)
{
category = category + Environment.NewLine + "Action Parameters : " + traceAction.Target.ToJSON(); //this ToJSON doesn't get resolved. which namespace should I include?
}
var record = new TraceRecord(request, category, level);
if (traceAction != null) traceAction(record);
Log(record);
}
There is no such method. The example from codeproject.com shows you how to make it yourself:
using System.Web.Script.Serialization;
using System.Data;
using System.Collections.Generic;
using System;
namespace WebApi.Helpers
{
public static class JSONHelper
{
/// <summary>
/// Extened method of object class, Converts an object to a json string.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static string ToJSON(this object obj)
{
var serializer = new JavaScriptSerializer();
try
{
return serializer.Serialize(obj);
}
catch(Exception ex)
{
return "";
}
}
}
}
A better way is to use JSON.Net. It is most likely already referenced in your project and System.Web.Extensions.dll is ancient nowadays (its performance is terrible):
public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
{
if (level != TraceLevel.Off)
{
if (traceAction != null && traceAction.Target != null)
{
category = category + Environment.NewLine + "Action Parameters : " + JsonConvert.SerializeObject(traceAction.Target);
}
var record = new TraceRecord(request, category, level);
if (traceAction != null) traceAction(record);
Log(record);
}
}

Getting "Cannot find installable ISAM" error

I'm facing a problem with my console application. I want to read info from Microsoft Access database and display it on console.
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data.Sql;
namespace _1_uzd
{
class Program
{
static void Main(string[] args)
{
string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=\"studentu-db.accdb\"";
OleDbConnection con = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand("SELECT * FROM persona", con);
con.Open();
OleDbDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
Console.WriteLine(dataReader.GetInt32(0) + "\t" + dataReader.GetString(1) + "\t" + dataReader.GetString(2));
}
con.Close();
Console.ReadLine();
}
}
}
It should work but when I debug, the error message is shown: "OleDbExeption was unhandled. Could not find installable ISAM"...Where is the problem?
PS: I'm using Microsoft Access 2007, it that makes any sense,
your connection string is not proper. that is main reason this error comes.
Try to correct connection string syntax as per http://www.connectionstrings.com/access/
Try with physical path like "C:\studentu-db.accdb" and if you are trying to locate access database from local folder then write "|DataDirectory|\studentu-db.accdb"

Resources