1
\$\begingroup\$

I'm relatively new to developing and I'm mostly self taught so a lot of what I know simply comes from googling & figuring things out from there!

That being said I've put together an ASP MVC WebApp that acts as an asset management system which works really well.

Now I'd like to expand that to mobile devices; however it needs to work offline and only with a small amount of of the functionality.

I plan on hiring a Android developer to put together something for me that will utilize Web Services that I use but before I start doing that I'd like to ask if anyone can have a look over what I've done and just tell me if I'm overlooking anything major... It is functional but I'm conscious it isn't up to the industry standard and I want to improve.

I'd really appreciate some feedback on what is wrong / not up to scratch with it & what I should focus on to improve this.

I chose WCF mostly at random - not sure if it is the best approach!

Thanks!

IWorkSvc.cs:

[ServiceContract]
public interface IWorkSvc
{
[OperationContract]
WebServiceResult AddEditWork(FmsWork w);

[OperationContract] 
List<WSRWorkReason> ListWorkReasons();

[OperationContract]
List<WSRVehicle> ListVehicles(string reg = null);

[OperationContract]
WebServiceResult MobileLogin(string userName, string password);
}

WorkSvc.svc:

public WorkSvc()
{
    IUnitOfWork uow = new UnitOfWork<FMSEntities>();
    _uow = uow;
    _workRepo = _uow.GetRepository<Work>();
    _secRepo = uow.GetRepository<SecurityGroup>();
    _groupRepo = uow.GetRepository<GroupPermission>();
    _itemRepo = _uow.GetRepository<WorkItem>();
    _reasonRepo = _uow.GetRepository<Reason>();
    _vehicleRepo = _uow.GetRepository<Vehicle>();
    _logonRepo = uow.GetRepository<LogonTracker>();
}

public List<WSRWorkReason> ListWorkReasons()
{
    DataTable dt = new DataTable();

    var data = _reasonRepo.Find(x => x.Active).ToList();
    var refinedData = data.Select(x => new WSRWorkReason()
    {
        ReasonId = x.Id,
        Reason = x.ReasonDescriptor
    }).ToList();

    return refinedData;
}

public List<WSRVehicle> ListVehicles(string reg = null)
{
    List<Vehicle> vehicleList = new List<Vehicle>();

    if (string.IsNullOrEmpty(reg))
    {
        vehicleList = _vehicleRepo.Find(x => x.Sold != true && x.Disposed != true).OrderBy(x => x.Registration)
            .ToList();
    }
    else
    {
        vehicleList = _vehicleRepo
            .Find(x => x.Sold != true && x.Disposed != true && x.Registration.Contains(reg.ToUpper()))
            .OrderBy(x => x.Registration).ToList();
    }

    var refinedData = vehicleList.Select(x => new WSRVehicle()
    {
        VehicleId = x.Id,
        Reg = x.Registration
    }).ToList();

    return refinedData;
}

public WebServiceResult AddEditWork(FmsWork w)
{
    WebServiceResult wsr = new WebServiceResult()
    {
        Type = "Work",
        Success = false,
        Message = "",
    };

    try
    {
        if (w != null)
        {
            Work work = new Work()
            {
                Id = w.Id,
                VehicleId = w.VehicleId,
                HoursOfLabour = w.HoursOfLabour,
                Description = w.Description,
                Date = w.Date,
                Notes = w.Notes,
                ReasonId = w.ReasonId,
                CreatedOn = DateTime.Now,
                CreatedBy = w.CreatedBy,
                ModifiedBy = w.ModifiedBy,
                ModifiedOn = w.ModifiedOn
            };

            if (w.Id > 0)
            {
                _workRepo.Update(work);
                wsr.Type = "Update";
            }
            else
            {
                _workRepo.Add(work);
                wsr.Type = "Update";
            }
            _uow.Save();

            wsr.Success = true;
            wsr.Message = "Successfully Added";
        }
    }
    catch (Exception e)
    {
        wsr.Message = e.Message;
        wsr.Success = false;
    }

    return wsr;
}

public WebServiceResult MobileLogin(string user, string password)
{
    WebServiceResult wsr = new WebServiceResult()
    {
        Action = "Mobile Login",
        Success = false,
        Type = "Mobile Login"
    };

    var strRoles = new string[] { };
    var strError = string.Empty;

    wsr.Success = (new LDAPAuth(ConfigurationManager.AppSettings["domain"]).MobileLogin(user, password,
        ref strRoles, ref strError));

    if (!wsr.Success)
    {
        wsr.Message = strError;
    }
    return wsr;
}
}

web.config: (This gave me a lot of trouble to start with!!)

<system.serviceModel>

<services>
  <service name="FMS.WebServices.WorkSvc" behaviorConfiguration="Behaviour1">

    <endpoint address="http://localhost:65166/WebServices/WorkSvc.svc" contract="FMS.WebServices.IWorkSvc" binding="basicHttpBinding" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="Behaviour1">
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="24:0:0" sendTimeout="24:0:0" openTimeout="24:0:0">
      <security mode="None">
        <transport clientCredentialType="None" />
        <message establishSecurityContext="false" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
\$\endgroup\$
2
  • \$\begingroup\$ WCF service and asp-mvc? Somehow it doesn't match. I don't think it's asp-mvc. \$\endgroup\$
    – t3chb0t
    Jun 12 '17 at 14:22
  • \$\begingroup\$ It's hosted on ASP MVC 5. Based on that response I'm sensing I've not chosen the best web-service platform? What would you recommend? \$\endgroup\$
    – Paul Evans
    Jun 12 '17 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.