European Silverlight 4 & Silverlight 5 Hosting BLOG

BLOG about Silverlight 5 Hosting and Its Techologies - Dedicated to European Windows Hosting Customer

European Silverlight 4 Hosting :: How to Edit Silverlight Page Data Using Domain Service

clock July 21, 2011 05:33 by author Scott

This post requires to create a Silverlight Business Application in Visual Studio 2010.

1. Open the Mainpage.xaml , Add the following XAML code to see the Save changes and Reject changes button

   1: <Button Content="Save Changes" Click="SaveButton_Click"
         Margin="5" 
   2:        x:Name="SaveButton"></Button>
   3: <Button Content="Reject Changes" Click="RejectButton_Click"
               Margin="5"
   4:         x:Name="RejectButton"></Button>
   5: <TextBlock x:Name="ChangeText" VerticalAlignment="Center"
      Width="Auto"></TextBlock>

2. Add the code for button click event handlers as shown below

   1: private void SaveButton_Click(object sender, RoutedEventArgs e)
   2:  {
   3:   awDept.SubmitChanges(OnSubmitCompleted, null);
   4:  }
   5: 
   6:  private void RejectButton_Click(object sender, RoutedEventArgs e)
   7:  {
   8:    awDept.RejectChanges();
   9:    CheckChanges();
  10:  }
  11: private void CheckChanges()
  12:  {
  13:   EntityChangeSet changeSet = awDept.EntityContainer.GetChanges();
  14:   ChangeText.Text = changeSet.ToString();
  15:   bool hasChanges = awDept.HasChanges;
  16:   SaveButton.IsEnabled = hasChanges;
  17:   RejectButton.IsEnabled = hasChanges;
  18:  }
  19: 
  20: private void OnSubmitCompleted(SubmitOperation so)
  21:  {
  22:    if (so.HasError)
  23:     {
  24:         MessageBox.Show(string.Format("Submit Failed: {0}", so.Error.Message));
  25:         so.MarkErrorAsHandled();
  26:      }
  27:             CheckChanges();
  28:  }

  29: private void departmentDataGrid_RowEditEnded(object sender,
          DataGridRowEditEndedEventArgs e)
  30: {
  31:          CheckChanges();
  32: }

3. Open the Metadata file in server project and add the editable attribute to the Id and modified date as shown below

   1: internal sealed class DepartmentMetadata
   2:         {
   3: 
   4:             // Metadata classes are not meant to be instantiated.
   5:             private DepartmentMetadata()
   6:             {
   7:             }
   8: 
   9:             [Editable(false)]
  10:             public short DepartmentID { get; set; }
  11: 
  12:             public string GroupName { get; set; }
  13:             [Editable(false)]
  14:             public DateTime ModifiedDate { get; set; }
  15: 
  16:             public string Name { get; set; }
  17:         }

4. When you run the application you should be able to see the below screen



European Silverlight WCF Hosting :: WCF AJAX Service Without Configuration

clock July 12, 2011 06:58 by author Scott

This post discusses how to develop Windows Communication Foundation (WCF) service using AJAX and without any configuration settings for WCF. This service can be consumed from Javascript. The service uses a special setting in .svc file which automatically enables an AJAX endpoint.

You can get the AJAX support for WCF through the ScriptManager control.

1. Create a WCF service project in VS 2010

The service contract code as follows

   1: // Define a service contract.
   2:   [ServiceContract(Namespace = "ConfigFreeWCFAjaxService")]
   3:   public interface ICalculator
   4:   {
   5:       [OperationContract]
   6:       double Add(double n1, double n2);
   7:   }

Service Implementation code as follows

   1: public class CalculatorService : ICalculator
   2: {
   3:     public double Add(double n1, double n2)
   4:     {
   5:         return n1 + n2;
   6:     }
   7: }

The SVC file setting as below

   1: <%@ServiceHost
   2:     language="c#"

   3:     Debug="true"
   4:     Service="ConfigFreeWCFAjaxService.CalculatorService"

   5:     Factory="System.ServiceModel.Activation.

          WebScriptServiceHostFactory"
   6: %>

WebScriptServiceHostFactory automatically add the WebScriptEndpoint to the service.

You need to add the following line in script manager control to call the service from javascript

   1:
<asp:ScriptManager ID="ScriptManager" runat="server">
   2:
     <Services>
   3:
         <asp:ServiceReference Path="service.svc" />
   4:
     </Services>
   5:
</asp:ScriptManager>

Calling the service from javascript

<script type="text/javascript">

  function makeAJAXCall()


   {

   var n1 = document.getElementById("num1").value;


   var n2 = document.getElementById("num2").value;

   // Instantiate a service proxy

   var proxy = new  ConfigFreeWCFAjaxService.ICalculator();

  // Call correct operation on proxy      
  proxy.Add(parseFloat(n1), parseFloat(n2), onSuccess, onFail, null);           
  break;


  }

</script>

//This function is called when the result from the service call is received

    function onSuccess(mathResult)

     {

        document.getElementById("result").value = mathResult;


    }

The <system.ServiceModel> element can be completely removed from the web.config if you configure your service as shown in the above.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2012 HostingASP.NET 4.5 HostingASP.NET MVC 5 Hosting, and SQL 2014 Hosting.

Tag cloud

Sign in