Regards,
I am trying to call a webservice from within the library of windows phone application that I am creating, however I have a weird problem and I hope that you can help me.
First of all I have the following code on my Application main page:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Library;
using System.Threading;
namespace Host
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
Class1.AsyncCall test = new AsyncCall();
test.Call("0002145", 51);
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
My AsyncCall class is in my library and it has the following code:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Threading;
using Library;
using Library.WebserviceRemote;
namespace Library
{
public class AsyncCallWS
{
WebserviceCall com = new WebserviceCall();
com.methodOne("methodOne", "1221", 122);
}
}
My WebserviceCall is another class in library and the method that is called looks like this:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//using System.ServiceModel;
using Library.WebserviceRemote;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace Library
{
//[DebuggerNonUserCode]
public class WebserviceCall
{
public void methodOne(String Method, String param1, int param2)
{
WebserviceRemote client = new WebserviceRemote ();
System.Diagnostics.Debug.WriteLine("I am in methodOne " + param1 + param2);
client.methodOneOnServiceCompleted += new EventHandler<methodOneOnServiceCompletedEventArgs>(client_methodOneOnServiceCompleted);
client.methodOneOnServiceAsync("1221", 122);
System.Diagnostics.Debug.WriteLine("After call to webservice ");
}
private void client_methodOneOnServiceCompleted(object sender, methodOneOnServiceCompletedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("This is the response " + e.Result);
}
}
}
Well the problem is that the method client_methodOneOnServiceCompleted is never read, the application never gets in it so I cannot get the response from webservice. I think it has something due to the EventHandler since this is all done in library not the applications page.
However, I am not aware why it doesn't get in that method. Furthermore, there are no errors and everything is there on output except this:
System.Diagnostics.Debug.WriteLine("This is the response " + e.Result);
Another notice: this code works like a charm when the call is made from within application itself but I really need to make webservice call from library, so please help :)
PS: this is all tested in emulator 7.0
Thank you.
Related
hey there I've just now started making a engine with tutorials while I was doing so I stumbled upon a error.
Here Is What the Error Told:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'ProjectBrowserDialg' could not be found (are you missing a using directive or an assembly reference?) Editor C:\Users\abrus\OneDrive\Documents\cpp_files_me\MehroofEngine\src\MehroofEngine For C++\Editor\MainWindow.xaml.cs 37 Active
this is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Editor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += OnMainWindowLoaded;
}
private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
{
Loaded -= OnMainWindowLoaded;
OpenProjectBrowserDialog();
}
private void OpenProjectBrowserDialog()
{
var projectBrowser = new ProjectBrowserDialg();
}
}
}
if I forgot something in the code please reply
if not enough information please reply it helps me make better posts.
I found same question in stack over flow as here and tried same think but still I am receiving ApplicationContext.Current as null.
I am making the web service where I need to pull out a couple of pieces of data from an Umbraco database. I don't need any of the Umbraco views or any of that stuff. I'm new to the Umbraco Core libraries.
What I did was get a below reference to my new web service project
umbraco.dll
Umbraco.Core.dll
umbraco.DataLayer.dll
umbraco.editorControls.dll
umbraco.MacroEngines.dll
umbraco.providers.dll
Umbraco.Web.UI.dll
umbraco.XmlSerializers.dll
UmbracoExamine.dll
And the below class code where I am receiving ApplicationContext.Current as null
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Web.Mvc;
using umbraco.MacroEngines;
using Umbraco.Web;
using Umbraco.Web.WebApi;
using umbraco.NodeFactory;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using umbraco.cms.businesslogic.media;
using umbraco.BusinessLogic;
using System.Configuration;
using log4net;
using System.Reflection;
using Umbraco.Core.Logging;
using System.Web.Optimization;
using System.Web.Http;
using System.Data.SqlClient;
using System.Data;
using System.Web.Script.Serialization;
using System.Collections;
using System.Collections.Specialized;
using System.Web.UI.WebControls;
using Stripe;
using System.Web.UI;
using System.Text.RegularExpressions;
using System.Web.Configuration;
using System.Web.Security;
using Newtonsoft.Json;
using System.Net.Mail;
using System.Text;
using System.Net;
using System.IO;
public class RegisterUserController : UmbracoApiController
{
public static string UmbracoConnectionString = ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString;
public static IMemberService memberService = ApplicationContext.Current.Services.MemberService;// Here I am getting ApplicationContext.Current as null
}
But I am calling this class I am getting ApplicationContext.Current as null.
So because of that I have Many methods in this class which works on memberService and due to this null reference they are not working. Even other methods which are not using member service are not being called.
For me, the code below seems to work.
public class TestApiController : UmbracoApiController
{
private static string _umbracoConnectionString = ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString;
private static IMemberService _memberService = global::Umbraco.Core.ApplicationContext.Current.Services.MemberService;
public int GetTest()
{
var memberCount = _memberService.Count();
return memberCount;
}
}
If the above code isn't working for you e.g. with AJAX, try the below code:
public class TestApiController : UmbracoApiController
{
public int GetTest()
{
var ms = Services.MemberService;
return ms.Count();
}
}
I have a WPF window with a combo box. The contents of the combo box should be populated from a column in a SQL table. I created a LINQ To SQL Data Context Class in a models folder and set the ItemsSource of the ComboBox to the class (Customers) generated by the data context.. But when I run the program, the contents of the combobox are the types of the items it pulled..
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using eTouchLV.GatekeeperUI.Models;
namespace eTouchLV.GatekeeperUI
{
public partial class MainWindow : Window
{
SQLDataClassDataContext dc = new SQLDataClassDataContext(Properties.Settings.Default.GatekeeperDBConnectionString);
public MainWindow()
{
InitializeComponent();
AssignDataToComponents();
}
private void AssignDataToComponents()
{
this.CheckDBIsValid();
comboCustomers.ItemsSource = dc.Customers;
}
private void CheckDBIsValid()
{
if (!dc.DatabaseExists())
{
MessageBox.Show("Program started on the machine but can't seem to find the database...", "Error connecting to DB on SQL server.");
}
}
}
}
Program:
I am VS 2012 silverlight-5 beginner. I tried to serialize and de-serialize from a xml file. I have following error while doing this :
The type or namespace name 'Serializable' does not exist in the namespace 'System' (are you missing an assembly reference?)
The type or namespace name 'SerializableAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DatamemberAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Datamember' could not be found (are you missing a using directive or an assembly reference?)
My code for serialization is :
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization.Json;
using System.Runtime;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
namespace Model.XML
{
public static class Serialization<T> where T : class
{
public static T DeserializeFromXmlFile(string fileName)
{
if (!File.Exists(fileName))
{
return null;
}
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
using (Stream stream = File.OpenRead(fileName))
{
return (T)deserializer.ReadObject(stream);
}
}
}
}
But i am interested in having each class seperately (not all the 3 classes (parameter,component and attribute) obtained in one class).
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization.Json;
using System.Runtime;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
using System.Xml.Serialization.XmlTypeAttribute;
using System.Serializable; //It gives red line under Serializable
namespace Model.XML
{
[Serializable] //It gives red line
public class attribute
{
[Datamember] //It gives red line
public string name { get; set; }
[Datamember] //It gives red line
public string label { get; set; }
[Datamember] //It gives red line
public string unit { get; set; }
[Datamember] //It gives red line
public component thisComponent { get; set; }
}
}
i tried to reference using System.Serializable; but it is not available in the dll list i have in my VS2012.
What is the cause of problem and how to get a rid of it ? Thanks in advance.
EDIT AFTER Comments:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization.Json;
using System.Runtime;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
using System.Collections.Generic;
namespace Model.XML
{
[DataContract]
public class attribute
{
[DataMember]
public string type { get; set; }
[DataMember]
public string displayed { get; set; }
[DataMember]
public string add_remove { get; set; }
[DataMember]
public string ccypair { get; set; }
[DataMember]
public List<int> item { get; set; }
public static void Main()
{
attribute Obj1 = Serialization<attribute>.DeserializeFromXmlFile("C:\\Users\\SHEK\\Desktop\\VannakNew\\DEV_CENTER\\Model\\XML\\XmlParameter.xml");
// Obj1.type = "shekhar";
}
}
}
And serialization.cs is :
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization.Json;
using System.Runtime;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
namespace Model.XML
{
public static class Serialization<T> where T : class
{
public static T DeserializeFromXmlFile(string fileName)
{
if (!File.Exists(fileName))
{
MessageBox.Show("File Path is wrong");
return null;
}
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
using (Stream stream = File.OpenRead(fileName))
{
return (T)deserializer.ReadObject(stream);
}
}
}
}
Xml file is XmlParameter.xml
<?xml version="1.0" encoding="utf-8" ?>
<parameter>
<name>bands_amounts</name>
<label>Bands Amounts</label>
<unit></unit>
<component>
<type>List</type>
<attributes>
<type>Integer</type>
<displayed>4</displayed>
<add_remove>yes</add_remove>
<item>1 000 000</item>
<item>5 000 000</item>
<item>10 000 000</item>
<item>20 000 000</item>
</attributes>
<attributes>
<ccypair>XAUUSD</ccypair>
<item>100</item>
<item>500</item>
<item>1000</item>
</attributes>
</component >
</parameter>
**It is working without error but i wonder why it always null object(on debugging) even the path of XmlParameter.xml file is correct. Is it due to using "[DataContract]" instead of [Serialized] ? because it si silverlight application. Actually i have todisplay the elements inside the nodes like,i have to display "XAUUSD" in my attribute.cs class which present in node <ccypair>XAUUSD</ccypair> **
There is no System.Serializable namespace; the SerializableAttribute class is in the System namespace. You should just write using System;.
I think you're confusing C# using statements with Java import statement. In Java, you import specific classes (or all classes from a package with *). In C#, the using statement imports all types in the specified namespace.
Currently, specifying a class name after using is an error, but in C# 6 it will be possible, and will import all static members from the class.
Other issue: you wrote Datamember instead of DataMember; C# is case sensitive. And anyway, DataMember has no effect on a class that doesn't have the DataContract attribute.
Also make sure you have referenced the System.Runtime.Serialization assembly.
I got the same problem and by adding this resolved the problem
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
Just add
using System.Runtime.Serialization;
This can also be caused if the application was targeted for .NET 2.0 but your are compiling if for a different .NET version/stack.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using MySql.Data;
using System.Web.Security;
using System.Data;
using System.IO;
using SurelyKnown.Core;
using System.Configuration;
using System.Collections;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Xml;
using System.Windows.Forms;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod(EnableSession = true)]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
int newOrgID = Convert.ToInt32(Session["uOrgID"].ToString());
The error is on the last line
CS0120: An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'
WHat should I do to get the session value inside the method.
Use HttpContext.Current.Session
int newOrgID=0;
if(HttpContext.Current.Session["uOrgID"]!=null)
{
int.TryParse(HttpContext.Current.Session["uOrgID"].ToString(),out newOrgID);
}
check for null before using it, something like this:
if(Session["uOrgID"] != null)
{
int newOrgID = Convert.ToInt32(Session["uOrgID"].ToString());
}
You should also read this article to really understand how to access Session state from web services (including web and page methods): Using ASP.NET Session State in a Web Service