Tuesday, 28 July 2015

WCF REST Sample with RSharper

RESET SERVICE


[ServiceContract]
public interface IAtolApcService
    {
        /// <summary>
        /// Submits the atol return.
        /// </summary>
        [OperationContract]
        [WebInvoke(Method = "POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate= "SubmitAtolReturn")]
        void SubmitAtolReturn(AtolReturn atolReturn);
}

Web Config Changes

  <behaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="serviceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
<services>
  <service behaviorConfiguration="serviceBehaviour" name=" WcfService.AtolApcService">
        <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="restBinding" contract=" WcfService.IAtolApcService" />
      </service>
    </services>


RESET Client

using Newtonsoft.Json;
using RestSharp;

public static void SubmitAtolReturn(AtolReturn atolReturn)
        {
            string resource = "/SubmitAtolReturn";

            var client = new RestClient(System.Configuration.ConfigurationManager.AppSettings["RESTUrl"].ToString());
            var request = new RestRequest(resource, Method.POST) { RequestFormat = DataFormat.Json };
            var json = JsonConvert.SerializeObject(atolReturn);

            //request.AddUrlSegment("atolLicenceGuid", AtolLicenceGUID);
            //request.AddUrlSegment("portalUsername", PortalUsername);
            request.AddParameter("application/json", json, ParameterType.RequestBody);

            var fullURL = System.Configuration.ConfigurationManager.AppSettings["RESTUrl"].ToString() + request.Resource;

            var response = client.Execute(request);
            switch (response.ResponseStatus)
            {
                case ResponseStatus.Completed:
                    break;
                case ResponseStatus.Error:
                    throw new Exception(String.Format("errorpage.aspx?CallingMethod={0}&ErrorMessage={1}&RESTCall={2}", System.Reflection.MethodBase.GetCurrentMethod().Name, response.ErrorMessage, fullURL));

                default:
                    throw new Exception(String.Format("errorpage.aspx?CallingMethod={0}&ErrorMessage={1}&RESTCall={2}", System.Reflection.MethodBase.GetCurrentMethod().Name, response.ErrorMessage, fullURL));
            }

        }

Monday, 13 July 2015

Dynamics CRM Explorer missing from Visual Studio

After installed CRM developer tool kit some times the CRM explorer window doesn't popup when we open the solution.

In that case open the project solution file in notepad and make sure below information is there.


Global
  GlobalSection(CRMSolutionProperties) = preSolution
    SolutionIsBoundToCRM = TRUE
  EndGlobalSection
EndGlobal