Friday, March 30, 2012

How to create a Webservice in Visual studio 2010



Click on File->New ->project
Select the Asp.NET Empty Web Application and click so it will be creating a new Web application
In that you will be able to add the web service

In solution explore Right Click on the Project and select Add New Item




In  the New window opened you will be able to find Web Service  
Select that and Click Ok.                                           


So your new web Service has been created

In the code view, you can see lot of comments and C# code already written for you. You will also see that at the bottom, there is a method HelloWorld which is written for you by default, so you can test your service and of course say hello to the world.below is the code which is generated by default...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebApplication1
{
    ///

    /// Summary description for WebService1
    ///

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

Wednesday, March 28, 2012

REST and SOAP

REST


REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used.


REST is an architecture style for designing networked applications. The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.
  • In many ways, the World Wide Web itself, based on HTTP, can be viewed as a REST-based architecture.
RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.
REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP, WSDL, et al.). Later, we will see how much more simple REST is.
  • Despite being simple, REST is fully-featured; there's basically nothing you can do in Web Services that can't be done with a RESTful architecture.
REST is not a "standard". There will never be a W3C recommendataion for REST, for example. And while there are REST programming frameworks, working with REST is so simple that you can often "roll your own" with standard library features in languages like Perl, Java, or C#.
SOAP
SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
Or more simply: SOAP is a protocol for accessing a Web Service.

Why SOAP?

It is important for application development to allow Internet communication between programs.


Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic.
A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this.
SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.

  • SOAP stands for Simple Object Access Protocol
  • SOAP is a communication protocol
  • SOAP is for communication between applications
  • SOAP is a format for sending messages
  • SOAP communicates via Internet
  • SOAP is platform independent
  • SOAP is language independent
  • SOAP is based on XML
  • SOAP is simple and extensible
  • SOAP allows you to get around firewalls
  • SOAP is a W3C recommendation

Monday, March 12, 2012

Silverlight CRM SOAP Library

SilverCrmSoap is a library built using the methods in the walkthrough to use the SOAP Endpoint for Web Resources with Silverlight to simplify Silverlight development for CRM 2011, providing a set of tools to make writing SOAP based Silverlight applicaiton for CRM easier and quick


Here is the link for codeplex which you can download  Silverlight CRM SOAP Library 

Silverlight CRM SOAP Library

Invalid cross-thread access

when we try to update UI elements from a different thread in Silver light ( asynchronous callbacks such as xml, json, WCF), we will run into invalid cross-thread access error if a “Dispatcher.BeginInvoke” is not used.
In most cases we can use the following and it will work fine.

    this.Dispatcher.BeginInvoke(delegate()
            {
                //do something here
            });

However, this won’t work on static functions/methods, because for the most obvious reason, “this” can not be used in static function.

System.Windows.Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                   //do something here
                });

System.Windows.Deployment.Current.Dispatcher.BeginInvoke should always be used to avoid invalid cross-thread access error.



Copied from:- http://mostup.com/2010/05/14/silverlight-invalid-cross-thread-access/

Wednesday, March 7, 2012

How to use “ClientGlobalContext.js.aspx”


When you work with HTML web resources, There might be situations where you need data about the CRM. “ClientGlobalContext.js.aspx”  gives  the  Context information out side of the CRM FORM so if you are not giving your clientGlobalContext.js.aspx file path in you webresource  according to how you are hosting your web resource.So if the path you are given is incorrect then it will be throwing error like this  "Failed to Invoke: GetGlobalContext." or in html page it will show like the following image

So you have to give you javascript correctly like the below code

 type="text/javascript" src="../../ClientGlobalContext.js.aspx"


Here is a Link which will explain you how to give the clientGlobalContext.js.aspx path according to the webresource  created in your CRM