c# - CRM Dynamics 2015 Plugin Cast Error, Specified Cast Is not valid -


below snippet of code plugin, added wcf service consumed(code) well.

plugin code below

if (context.inputparameters.contains("target") &&  context.inputparameters["target"] entity)             {              entity phonecallentity = (entity)context.inputparameters["target"];              if (phonecallentity.logicalname != "phonecall")                 return;              if (context.messagename == "create")             {                 try                 {                      int numbertocall = phonecallentity.attributes.contains("phonenumber") ? (int)phonecallentity.attributes["phonenumber"] : 0;                     int receivecallon = phonecallentity.attributes.contains("new_destination") ? (int)phonecallentity.attributes["new_destination"] : 0;                     string apikey = phonecallentity.attributes.contains("new_apikey") ? phonecallentity.attributes["new_apikey"].tostring() : null;                     int fid = phonecallentity.attributes.contains("new_fid") ? (int)phonecallentity.attributes["new_fid"] : 0;                      basichttpbinding binding = new basichttpbinding();                     binding.name = "basichttpbinding_iservice1"; 

here call service

 binding.sendtimeout = new timespan(0, 10, 0);  endpointaddress endpointaddress = new endpointaddress("http://localhost:62009/service1.svc");  servicereference1.service1client client = new servicereference1.service1client(binding, endpointaddress);  client.webcall(numbertocall, receivecallon, apikey, fid); 

above call wcf service

public void webcall(int64 numbertocall, int64 receivecallon, string apikey, int fid)     {         string url = string.format("https://xxxx{0},{1},{2}", numbertocall, receivecallon, apikey, fid);         webrequest webrequest = webrequest.create(url);         webresponse webresp = webrequest.getresponse();         webrequest.method = "post";     } 

code snippet above actual wcf service being consumed, issue casting of number toi call , receivecallon number, both cell phone numbers , in crm phone data type, ideas why cannot cast this.

the field phonenumber entity phonecall single type of text (with format phone), means string (as custom field if field settings same) code can be:

string numbertocall = phonecallentity.contains("phonenumber") ? phonecallentity["phonenumber"].tostring() : ""; string receivecallon = phonecallentity.contains("new_destination") ? phonecallentity["new_destination"].tostring() : ""; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -