简体   繁体   中英

Cannot implicitly convert type are you missing a cast? Arrays, Enumerators and Web services

I am trying to send a soap message to an external system, this system already has predefined data types which I must integrate in my code, using arrays and enumerators.

My problem is the enumerator variables are giving me the following error:

Error 1 Cannot implicitly convert type 'UpdateRatePacks._Default.Rate.AvailAppType' to 'UpdateRatePacks.IService.AvailAppType?'. An explicit conversion exists (are you missing a cast?)

The error says it cannot convert the type on my page to the type on my webservice, but the data structures are the same, Have I missed something?

I have searched this error out everywhere,also searched out on enumerators in web service, enumerators in arrays, converting enumerators to arrays but nothing has worked. The error is still the same.

Even included this line of code for the parse conversion:

ureq.RatePackages[2].Rates[1].AvailabilityApplicationType = Rate.AvailAppType)Enum.Parse(typeof(Rate.AvailAppType), val);

The complexity of this code is it contains enumerators in arrays so I don't know whether I am going wrong in the enumerator or in the array itself or in the entire web service.

This is part of my code that sends the update as a message where the error comes from

 protected void SendSoapMessage()
 {

  Rate.AvailabilityApplicationType val  =  Rate.AvailAppType.SET;
  ureq.RatePackages[1].Rates[0].AvailAppType = val;

ureq is UpdateRatePacks method from the webservice I am sending to

Classes/ Objects defined below:

public class UpdateRatePacks
{
 public string Username;
 public string Password;
 public UpdateRatePack[] RatePackages;
}

    public class UpdateRatePack
    {
        public Int64 RatePackageId;
        public Rate[] Rates;

    }


    public class Rate
    {


        public enum AvailAppType { SET , INCREASE, DECREASE };


    }

Any advise would be greatly appreciated.

It looks like you're creating your own version of the AvailAppType enumeration, when its already available in the generated proxy code of the web service you're hitting. Use the generated proxy code's version of the enumeration, which is I believe UpdateRatePacks.IService.AvailAppType? as the type rather than define your own. Even though they have the same enumeration names, they're in separate namespaces rendering them different in the eyes of the compiler.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM