• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

.Net C# web service not all code paths return a value

I am getting the following error I understand I am missing something but I have no idea what as I am still learning. Any help would be great

error message:

------ Build started: Project: e:\projects\ChromeWebService\, Configuration: Debug .NET ------
Validating Web Site
Building directory '/ChromeWebService/App_WebReferences/'.
Building directory '/ChromeWebService/App_Code/'.

e:\projects\ChromeWebService\App_Code\ChromeWebService.cs(27,19): error CS0161: 'ChromeWebService.getVin()': not all code paths return a value
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========


Here is the code:


using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.chrome.platform.AutomotiveDescriptionService5;




/// <summary>
/// Summary description for ChromeWebService
/// </summary>
[WebService(Namespace = "http://arknet.arkona.com/ChromeWebService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ChromeWebService : System.Web.Services.WebService {

    public ChromeWebService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();


    }

    [WebMethod]
    public string getVin()
    {

        AutomotiveDescriptionService5 ads = new AutomotiveDescriptionService5();

        AccountInfo accountInfo = new AccountInfo();
        accountInfo.accountNumber = "xxxxxxxx";
        accountInfo.accountSecret = "xxxxxxxxxxxx";
        accountInfo.locale = new Locale();
        accountInfo.locale.language = "en";
        accountInfo.locale.country = "US";
        String Vin = "";
        String manufactureModelCode = "";
        String trimName = "";
        String manufactoureOptionCodes = "";
        String equipmentDescriptions = "";
        String wheelBase = "";
        String exteriorColorName = "";
        String useSafeStandards = "";
        String excludeFleetOnlyStyles = "";
        String includeAvailableEquipment = "";
       


        String version = "";
        DataVersionsRequest dataVersionRequest = new DataVersionsRequest();
        dataVersionRequest.accountInfo = accountInfo;
        DataVersion[] dataVersions = ads.getDataVersions(dataVersionRequest);
        for (int i = 0; i < dataVersions.Length; i++)
        {
            if (dataVersions[i].country == "US")
            {
                version = dataVersions[i].country + " " + dataVersions[i].build + " (" +
                    dataVersions[i].date + ")";
            }
        }

        VehicleInformation vehicleInfo = null;
        if (Vin != null && Vin.Length > 0)
        {
            VehicleInformationFromVinRequest vinRequest = new
                VehicleInformationFromVinRequest();
            vinRequest.accountInfo = accountInfo;

            vinRequest.vin = Vin;
            vinRequest.manufacturerModelCode = manufactureModelCode;
            vinRequest.trimName = trimName;
            if (manufactoureOptionCodes.Length > 0)
            {
                vinRequest.manufacturerOptionCodes = manufactoureOptionCodes.Split(new char[] { ',' });
            }
            if (equipmentDescriptions.Length > 0)
            {
                vinRequest.equipmentDescriptions = equipmentDescriptions.Split(new char[] { ',' });
            }
            if (wheelBase.Length > 0)
            {
                vinRequest.wheelBase = Double.Parse(wheelBase);
            }
            vinRequest.exteriorColorName = exteriorColorName;
            vinRequest.useSafeStandards = useSafeStandards != null;
            vinRequest.excludeFleetOnlyStyles = excludeFleetOnlyStyles != null;
            vinRequest.includeAvailableEquipment = includeAvailableEquipment != null;

            vinRequest.enableEnrichedVehicleEquipment = false;

            vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);


        }
 
    }

}

Thank you for taking the time to look at this.
0
jareddraper
Asked:
jareddraper
  • 3
  • 2
1 Solution
 
HardiCommented:
not all code paths return a value --> If a function return string, then you have to make it return a string when you return from the function.

perhaps in this function
public string getVin()
you need to return a string at the end

otherwise change it to
public void getVin()
0
 
HardiCommented:
Perhaps something like this
        if (Vin != null && Vin.Length > 0)
        {
            //.... your code.....

            vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);

            return vehicleInfo.ToString(); //or any method/property of vehicleInfo that is a string
        }
        else
        {   return "";  }
0
 
jareddraperAuthor Commented:
Thank you both I figured it was something like this but didn't know how to complete what it was doing. Thank you both I will try both and see which works better.
0
 
jareddraperAuthor Commented:
ha just noticed Hardi you posted both Thank you
0
 
HardiCommented:
Hahaha no worries, glad to help :-D
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now