I am using a SAP web service and I am using BCS to get the external data. However, when I try to create a new item via code I get this error:
Stack trace:
The remote server returned an error: (500) Internal Server Error.
at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataConnection.ThrowBCSException(WebException webException) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataConnection.ExecuteRequest(IBCSODataRequest requestMsg) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataDirectConnection.ExecuteRequest(IBCSODataRequest requestMsg) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataConnection.ExecuteODataServiceRequest(String odataUrl, String httpMethod, String mimeType, IDictionary`2 requestHeaders, Boolean encodeRequest, IList`1 inputValues) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataServiceProxy.ExecuteInternal(String httpMethod, String mimeType, ODataConnection odataConnection, IMethodInstance methodInstance, IParameterCollection methodInputParameters, Object[] methodInputArgs, IParameter parameterWithDirectionReturn, PayloadKind payloadType, Boolean setupParameters, Boolean encodeRequest) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataServiceProxy.InvokeODataService(ODataConnection odataConnection, IMethodInstance methodInstance, IParameterCollection methodInputParameters, Object[] methodInputArgs, IParameter parameterWithDirectionReturn) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataServiceProxy.Execute(IMethodInstance methodInstance, IParameterCollection methodInputParameters, Object[] methodInputArgs, IParameter parameterWithDirectionReturn) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataSystemUtility.ExecuteInternal(IMethodInstance methodInstance, Object[]& methodSignatureArgs) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataSystemUtility.Execute(Object[] args) at Microsoft.SharePoint.BusinessData.SystemSpecific.OData.ODataSystemUtility.ExecuteStatic(IMethodInstance methodInstance, ILobSystemInstance lobSystemInstance, Object[] args, IExecutionContext context) at Microsoft.SharePoint.BusinessData.Runtime.DataClassRuntime.ExecuteInternalWithAuthNFailureRetry(ISystemUtility systemUtility, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, ILobSystemInstance lobSystemInstance, ILobSystem lobSystem, IParameterCollection nonReturnParameters, Object[] overrideArgs) at Microsoft.SharePoint.BusinessData.Runtime.DataClassRuntime.ExecuteInternal(IDataClass thisDataClass, ILobSystemInstance lobSystemInstance, ILobSystem lobSystem, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, IParameterCollection nonReturnParameters, Object[]& overrideArgs) at Microsoft.SharePoint.BusinessData.Runtime.EntityRuntime.ExecuteInternal(IDataClass thisDataClass, ILobSystemInstance lobSystemInstance, ILobSystem lobSystem, IMethodInstance methodInstanceToExecute, IMethod methodToExecute, IParameterCollection nonReturnParameters, Object[]& overrideArgs, IFilterCollection filters) at Microsoft.SharePoint.BusinessData.Runtime.EntityRuntime.Create(IEntity thisEntity, IFieldValueDictionary fieldValues, Identity identity, AssociationEntityInstancesDictionary associationInfo, ILobSystemInstance lobSystemInstance) at Microsoft.SharePoint.BusinessData.MetadataModel.Static.Entity.Create(IFieldValueDictionary fieldValues, ILobSystemInstance lsi) at VisualWebPartProject1.CreateDossier.CreateDossier.Button1_Click(Object sender, EventArgs e)
Here is my code:
using (new SPServiceContextScope(SPServiceContext.GetContext(SPContext.Current.Site)))
{
// Get the BDC service and metadata catalog.
BdcService service = SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
IMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);
// Get the entity using the specified name and namespace.
IEntity entity = catalog.GetEntity("NSpace", "EntName");
ILobSystemInstance lobSysteminstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;
// Get the fields on the entity.
IView createView = entity.GetCreatorView("CreateItem");
IFieldValueDictionary valueDictionary = createView.GetDefaultValues();
// Set the values of the entity fields.
//valueDictionary["CustomerId"] = Convert.ToString(myRandomNumber);
valueDictionary["fiw_zztype_de_dmnd"] = "";
valueDictionary["fiw_zzdoss_type"] = "";
valueDictionary["fiw_zzsimpl_doss"] = "";
valueDictionary["fiw_p"] = "";
valueDictionary["fiw_g"] = "";
valueDictionary["fiw_e"] = "";
valueDictionary["fiw_uname"] = "";
valueDictionary["fiw_language"] = "";
entity.Create(valueDictionary, lobSysteminstance);
}