I was struggling of calling a webservice if the user logs off in Silverlight client. For me to solve the problem I called the service in server side using javascript. Here's how to:
function sendDataAsXML_SOAP() { var req_params = "", url = "", number = 0, type = ""; /* Configure Parameters */ url = "http://localhost/TempWS/MachineHistoryWS.asmx"; user = "129272802615082804";
req_params = ""; req_params = req_params + ""; req_params = req_params + "" + user + ""; alert(req_params); /* Send XML/SOAP Request To Web Service Using Browser's Javascript DOM */ try { ajax_request = new XMLHttpRequest(); } catch (trymicrosoft) { try { ajax_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { ajax_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { ajax_request = false; } } } ajax_request.open("POST", url, true); ajax_request.setRequestHeader("Content-Type", "text/xml;charset=utf-8"); ajax_request.onreadystatechange = receiveXML_SOAPData; ajax_request.send(req_params); }
Peer-to-Peer(P2P) architecture is a serverless architecture. In a peer mesh network, in order for them to be considered and classified as peer, first, the node needs to be included in a peer mesh layer. To do so, their are two options. First by using PNRP(Peer Name Resolution Protocol) and Custom Peer Resolver.
Steps:
1. You need to have an EventBehaviourFactory class. You can copy this code.
public static class EventBehaviourFactory
{
public static DependencyProperty CreateCommandExecutionEventBehaviour(RoutedEvent routedEvent, string propertyName, Type ownerType)
{
DependencyProperty property = DependencyProperty.RegisterAttached(propertyName, typeof(ICommand), ownerType,
new PropertyMetadata(null,
new ExecuteCommandOnRoutedEventBehaviour(routedEvent).PropertyChangedHandler));
return property;
}
/// /// An internal class to handle listening for an event and executing a command,
/// when a Command is assigned to a particular DependencyProperty
/// private class ExecuteCommandOnRoutedEventBehaviour : ExecuteCommandBehaviour
{
private readonly RoutedEvent _routedEvent;
public ExecuteCommandOnRoutedEventBehaviour(RoutedEvent routedEvent)
{
_routedEvent = routedEvent;
}
/// /// Handles attaching or Detaching Event handlers when a Command is assigned or unassigned
/// ///
///
///
protected override void AdjustEventHandlers(DependencyObject sender, object oldValue, object newValue)
{
UIElement element = sender as UIElement;
if (element == null) { return; }
if (oldValue != null)
{
element.RemoveHandler(_routedEvent, new RoutedEventHandler(EventHandler));
}
if (newValue != null)
{
element.AddHandler(_routedEvent, new RoutedEventHandler(EventHandler));
}
}
protected void HandleEvent(object sender, EventArgs e)
{
DependencyObject dp = sender as DependencyObject;
if (dp == null)
{
return;
}
ICommand command = dp.GetValue(_property) as ICommand;
if (command == null)
{
return;
}
if (command.CanExecute(e))
{
command.Execute(e);
}
}
/// /// Listens for a change in the DependencyProperty that we are assigned to, and
/// adjusts the EventHandlers accordingly
/// ///
///
public void PropertyChangedHandler(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
// the first time the property changes,
// make a note of which property we are supposed
// to be watching
if (_property == null)
{
_property = e.Property;
}
2. Create a relay command class which inherits ICommand Interface. You can copy this code. An ICommand contains methods to execute commands. A command can be executed many times, and the parameter values can vary. This interface is mandatory on commands.
Namespace: System.Windows.Input
Assembly: PresentationCore (in PresentationCore.dll)
public class RelayCommand:ICommand
{
#region private fields
readonly Action
var navResultsPlant = LogXmlDocument.Descendants().Where( e => e.Attribute("id").Value == id).FirstOrDefault(); if (navResultsPlant != null) navResultsPlant.Remove();
Today, I've learned how to use caliburn framework in Model-View-View Model(MVVM) designed pattern. Without using the application framework, you can set your event in your view.xaml by this:
in your view.cs, you need to hard code this: void MouseEnter(object sender, MouseEventArgs e) { //code here }
using the implementation above, it breaks the rule of MVVM, the view classes have no idea that the model classes exist, while the ViewModel and model are unaware of the view.
but using caliburn, you need to add this to your view.xaml by
in your viewmodel.cs, public void OnMouseEnter(MouseEventArgs e) { //code here }
LogXmlDocument.Add (new XElement ("Property", new XAttribute("id", newid), new XAttribute("iid", sid), new XElement("Identification", id), new XElement("Description", desc), new XElement("Manufacturer", manufac) );
XDocument xmlFile = XDocument.Load(filename); var xt = from y in xmlFile.Descendants("Users").Elements("details") where y.Attribute("userName").Value == x select new TempClass { Name = y.Element("userdetails").Attribute("userFirstName").Value };