I am trying to create a web from (web application) in Visual Studio 2012 to push data into CRM 2015 online. It keep saying Metadata Contains A Reference That Cannot Be Resolved, when the program tried to call OrgService.
Before that, I create a windows form to do so, it works fine. It can connect to CRM 2015 online and create a new entity record successfully. But when I move the code to Web Application. I does not work.
Code:
private void button1_Click(object sender, EventArgs e)
{
ClientCredentials cre = new ClientCredentials();
cre.UserName.UserName = "MyEmailAddress";
cre.UserName.Password = "Password";
Uri serviceUri = new Uri("https://QA.crm.dynamics.com/XRMServices/2011/Organization.svc");
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, cre, null);//Error occurs here!!!!!!
proxy.EnableProxyTypes();
IOrganizationService service = (IOrganizationService)proxy;
Entity contact = new Entity("contact");
contact["firstname"] = Convert.ToString(firstname.Text);
contact["lastname"] = Convert.ToString(lastname.Text);
contact["emailaddress1"] = Convert.ToString(email.Text);
contact["mobilephone"] = Convert.ToString(phone.Text);
proxy.Create(contact);
}
Error occurs at:
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, cre, null);
Is there anyone know what is going on here? I appreciate your help.
Thanks.
Try to use following code for initialization of service proxy:
IServiceManagement<IOrganizationService> orgServiceManagement =
ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://democrm.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"));
AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = _userName;
authCredentials.ClientCredentials.UserName.Password = _password;
AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);
IOrganizationService organizationProxy = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);
Related
please help with this below code to change to oauth
// Create Server Configuration
ServerConnection.Configuration config = new ServerConnection.Configuration();
config.ServerAddress = serverAddress;
config.DiscoveryUri = new Uri(String.Format("xxx", config.ServerAddress));
config.OrganizationName = organizationName;
config.OrganizationUri = new Uri(String.Format("xxx", config.ServerAddress));
config.Credentials = credentials;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
crmServiceClient = new CrmServiceClient('xxx', credentials);
//dynamicsServiceProxy = ServerConnection.GetOrganizationProxy(config);
//dynamicsServiceProxy.EnableProxyTypes();
crmServiceClient.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new
ProxyTypesBehavior(Assembly.GetExecutingAssembly()));
Any one please help me what changes i need to do?
I have Read this article but how to replace IOrganizationService in code?
I'm new to custom workflow activities in Dynamics CRM 2016. I'm trying to download an image from url in the code below, the workflow is deployed in Dynamics crm online 2016. When I try to debug in visual studio the Plugin Registration Tool crashes without showing any errors at this line:
byte[] imageBytes = client.DownloadData(imageUrl);
Code:
private string ConvertImageToBase64(string imageUrl)
{
var base64String = string.Empty;
using (WebClient client = new WebClient())
{
byte[] imageBytes = client.DownloadData(imageUrl);==== Fails here.
base64String = Convert.ToBase64String(imageBytes);
}
return base64String;
}
I am trying to customize some lists for SharePoint Online and since I am new to the subject I do not know how to connect to the service.
When I use NAPA and from the cloud use the option "Edit in Visual Studio", I am prompted for credentials automatically when the project opens.
However, when I start from bottom-up, i.e. open a new project in Visual Studio, add all necessary dlls, this part of code throws an error (it is an authentication issue):
ClientContext context = new ClientContext("https://MYURL.sharepoint.com/n/");
context.ExecuteQuery();
I am using Microsoft.SharePoint.Client;
The error message:
An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll
Additional information: The remote server returned an error: (403) Forbidden.
I think I am missing part of the code which is responsible for authentication and which in case of NAPA app is hard-coded.
How can I authenticate to SharePoint Online? (it is enough if my code runs just once, it's not an app, I don't want to package it and publish)
I am guessing it has something to do with http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.sharepoint.remote.authentication.aspx, but that's as far as I got.
How to authenticate against SharePoint Online using the managed CSOM
The CSOM for SharePoint 2013 introduces the SharePointOnlineCredentials class that allows to perform an active authentication to SharePoint Online.
Example
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the URL of the SharePoint Online site:");
string webUrl = Console.ReadLine();
Console.WriteLine("Enter your user name (format: username#tenant.onmicrosoft.com)");
string userName = Console.ReadLine();
Console.WriteLine("Enter your password.");
SecureString password = GetPasswordFromConsoleInput();
using (var context = new ClientContext(webUrl))
{
context.Credentials = new SharePointOnlineCredentials(userName,password);
context.Load(context.Web, w => w.Title);
context.ExecuteQuery();
Console.WriteLine("Your site title is: " + context.Web.Title);
}
}
private static SecureString GetPasswordFromConsoleInput()
{
ConsoleKeyInfo info;
//Get the user's password as a SecureString
SecureString securePassword = new SecureString();
do
{
info = Console.ReadKey(true);
if (info.Key != ConsoleKey.Enter)
{
securePassword.AppendChar(info.KeyChar);
}
}
while (info.Key != ConsoleKey.Enter);
return securePassword;
}
}
I am trying to create a custom workflow in Visual Studio 2010 for SharePoint 2010 and have run into a problem. I have figured out how to deploy the workflow to the SharePoint site, but executing it results in an error. However, the error message is completely non-descriptive, so I want to find out if there is a way to execute it from Visual Studio so I can see where it fails, and possibly why.
I'm trying to simply create a new subsite based on a given ListItem.Title information.
How is it you go about debugging?
For reference, here is my code
class CreateSubsite : System.Workflow.ComponentModel.Activity
{
protected override System.Workflow.ComponentModel.ActivityExecutionStatus
Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
{
createSite();
return System.Workflow.ComponentModel.ActivityExecutionStatus.Closed;
}
public void createSite()
{
using (SPSite currentSite = SPContext.Current.Site)
{
using (SPWeb currentWeb = SPContext.Current.Web)
{
SPList currentList = SPContext.Current.List;
SPListItem currentListItem = SPContext.Current.ListItem;
WorkflowContext workflow = new WorkflowContext();
SPSite parentSite = new SPSite(workflow.CurrentWebUrl);
SPWeb newSite = currentSite.AllWebs.Add(
currentListItem.Title.Replace(" ", "_"),
currentListItem.Title,
String.Empty, currentWeb.Language, "CI Template", false, false
);
}
}
}
}
Try to remove Using keyword from your code .You should not dispose your SPSite and SPWeb when you use SPContext because disposing of that object might actually break the workflow as it may still need a reference to that object for later use.
just rewrite your code without use using
public void createSite() {
SPSite currentSite = SPContext.Current.Site
SPWeb currentWeb = SPContext.Current.Web
//.... Rest of your code
Hope that help
Regards.
CustomerService CustService = new CustomerService();
try
{
CustService.Credentials = new NetworkCredential("xxx", "xxx", "xxx");
AxdCustomer customer = new AxdCustomer();
AxdEntity_CustTable[] table = new AxdEntity_CustTable[1];
AxdEntity_CustTable test = new AxdEntity_CustTable();
test.AccountNum = TextBox1.Text;
test.Name = TextBox1.Text;
test.CustGroup = DropDownList1.SelectedItem.Value;
table[0] = test;
customer.CustTable = table;
CustService.create(customer);
}
catch (Exception ex)
{
err.Visible = true;
lblerr.Text = ex.Message;
}
I am new to Dynamics AX. I'm trying to create a customer which is actually created by consuming a webservice from the web . the above code snippet is the code for that, but it's giving an exception as :
Request Failed. See the Exception Log for details.
I'm not even getting the actual reason why it's not getting created. How to create a customer in dynamics AX 2009 sp1?
Note: CustService is the CustomerService object for the class in CustomerSvc namespace (it is the webservice reference to the CustomerService webservice in Dynamics).
Have a look at the event log in the server where there webservice and the AOS is hosted on.
You may get half a clue from there.
Also have a look at the exception log in AX which you can get from
Basic -> Periodic -> Application Integration framework -> Exceptions
Once you get the error details then you may figure out the problem otherwise post them here and I an have a further look at what the problem might be.