/// <summary> /// Gets a single Membership based on a Membership ID /// </summary> public Membership Get(string membershipId) { Guid id = Guid.Parse(membershipId); // fine if this crashes as the error handling will kick in. this._tracer.Trace("Method: MembershipService.Get"); this._tracer.Trace("Parameters: membershipId={0}", membershipId); Membership membership = null; try { if (id != Guid.Empty) { var sdk = ConnectionController.ConnectToCrm(this._tracer); if (sdk != null) { MembershipController mc = new MembershipController(sdk, this._tracer); membership = mc.GetMembership(id); this._tracer.Trace("membership is null={0}", membership == null); // if there is no membership found, throw an error back to the caller if (membership == null) { this._tracer.Trace("membership not valid"); throw new Exception("Membership is not valid for renewal"); } } else { string message = "Unable to connect to CRM. Check web.config"; this._tracer.Trace(message); throw new Exception(message); } } } catch (FaultException <OrganizationServiceFault> fe) { if (fe.Detail != null) { this._tracer.Trace(fe.Detail.ToString()); } this._tracer.Trace(fe.ToString()); throw new WebFaultException <Error>(ConvertToError(fe, DateTime.Now.Ticks.ToString()), HttpStatusCode.InternalServerError); } catch (Exception ex) { this._tracer.Trace(ex.ToString()); throw new WebFaultException <Error>(ConvertToError(ex, DateTime.Now.Ticks.ToString()), HttpStatusCode.InternalServerError); } finally { // write to the log file this._tracer.WriteToLog(this._logPath); } return(membership); }