Согласен думаю по коду будет проще понять в чем проблема:
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using SDK = Microsoft.Crm.Sdk;
using pluginUpdateKursperescheta.CrmSdk;
namespace pluginUpdateKursperescheta
{
public class onUpdateKp : SDK::IPlugin
{
public void Execute(SDK.IPluginExecutionContext context)
{
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = context.OrganizationName;
CrmService service = new CrmService();
RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
service.Url = String.Concat(regkey.GetValue("ServerUrl").ToString(), "/2007/crmservice.asmx");
service.CrmAuthenticationTokenValue = token;
service.UseDefaultCredentials = true;
//-----------------------------------------------------------------------------------------
SDK::DynamicEntity currentKp = context.PostEntityImages["KpIm"] as SDK::DynamicEntity;
try
{
if (currentKp.Properties.Contains("new_kursperesheta"))
{
ColumnSet cols = new ColumnSet()
{
Attributes = new string[] { "new_wholeamount" }
};
ConditionExpression cond = new ConditionExpression()
{
AttributeName = "quoteid",
Operator = ConditionOperator.Equal,
Values = new object[] { ((SDK::Key)currentKp.Properties["quoteid"]).Value }
};
FilterExpression filt = new FilterExpression()
{
Conditions = new ConditionExpression[] { cond }
};
QueryExpression query = new QueryExpression()
{
ColumnSet = cols,
EntityName = EntityName.quotedetail.ToString(),
Criteria = filt,
};
BusinessEntity[] buss = service.RetrieveMultiple(query).BusinessEntities;
decimal wholeamount = 0;
foreach (var item in buss)
{
wholeamount += ((quotedetail)item).new_wholeamount.Value;
}
ColumnSet colsTemp = new ColumnSet() { Attributes = new string[] { "new_temp_salesorderid" } };
ConditionExpression condTemp = new ConditionExpression()
{
AttributeName = "new_quoteid",
Operator = ConditionOperator.Equal,
Values = new object[] {((SDK::Key)currentKp.Properties["quoteid"]).Value }
};
FilterExpression filTemp = new FilterExpression()
{
Conditions = new ConditionExpression[] { condTemp }
};
QueryExpression queryTemp = new QueryExpression()
{
ColumnSet = colsTemp,
EntityName = EntityName.new_temp_salesorder.ToString(),
Criteria = filTemp
};
BusinessEntity[] bussTemp = service.RetrieveMultiple(queryTemp).BusinessEntities;
if (bussTemp.Length > 0)
{
new_temp_salesorder tempSales = new new_temp_salesorder();
tempSales.new_temp_salesorderid = new Key() { Value = ((new_temp_salesorder)bussTemp[0]).new_temp_salesorderid.Value };
tempSales.new_quoteid = ((SDK::Key)currentKp.Properties["quoteid"]).Value.ToString();
tempSales.new_totallineitemamount = new CrmMoney() { Value = wholeamount };
tempSales.new_discountamount = new CrmMoney() { Value = wholeamount - (wholeamount * ((SDK::CrmDecimal)currentKp.Properties["discountpercentage"]).Value / 100) };
tempSales.new_totaltax = new CrmMoney() { Value = tempSales.new_discountamount.Value * Convert.ToDecimal(0.18) };
tempSales.new_totalamount = new CrmMoney() { Value = tempSales.new_totaltax.Value + tempSales.new_discountamount.Value };
service.Update((BusinessEntity)tempSales);
}
else
{
new_temp_salesorder tempSales = new new_temp_salesorder();
tempSales.new_temp_salesorderid = new Key();
tempSales.new_name = ((SDK::Key)currentKp.Properties["quoteid"]).Value.ToString();
tempSales.ownerid = new Owner() { Value = ((SDK::Lookup)currentKp.Properties["createdby"]).Value };
tempSales.new_quoteid = ((SDK::Key)currentKp.Properties["quoteid"]).Value.ToString();
tempSales.new_totallineitemamount = new CrmMoney() { Value = wholeamount };
tempSales.new_discountamount = new CrmMoney() { Value = wholeamount - (wholeamount * ((SDK::CrmDecimal)currentKp.Properties["discountpercentage"]).Value / 100) };
tempSales.new_totaltax = new CrmMoney() { Value = tempSales.new_discountamount.Value * Convert.ToDecimal(0.18) };
tempSales.new_totalamount = new CrmMoney() { Value = tempSales.new_totaltax.Value + tempSales.new_discountamount.Value };
// тут падает service.Create((BusinessEntity)tempSales) Cannot call 'pluginUpdateKursperescheta.CrmSdk.CrmService.Create(pluginUpdateKursperescheta.CrmSdk.BusinessEntity)' because it is a web method.
service.Create((BusinessEntity)tempSales);
}
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new SDK::InvalidPluginExecutionException(
String.Format("An error occurred in the {0} plug-in.", this.GetType().ToString()), ex);
}
}
}
}