My client is using the hosted edition, and not the online version, of Dynamics CRM 2011. Using my C# code, how would I obtain the user name, password, URL and device ID to authenticate? Using the CRM 2011 online, I can connect using this code. I believe device ID is hard coded.
CrmConnection crmConnection = CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password=
{2};DeviceID=enterprise-ba9f6b7b2e6d; DevicePassword=passcode;", url, username, password));
OrganizationService service = new OrganizationService(crmConnection);
var xrm = new XrmServiceContext(service);
return xrm;
Hosted version (OnPremise) relies on Active Directory authentication (DOMAIN\USERNAME), so you need to add Domain to your connection string and remove DeviceID and DevicePassword (they are necessary only for CRM Online using LiveId authentication)
The code will be:
CrmConnection crmConnection =
CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain));
Try just delete deviceid and devicepassword. Also check this article that describes how to use CrmConnection class.
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
/This URL needs to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://crm/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
if (Context.User.Identity.IsAuthenticated)
{
string EUserName = Context.User.Identity.Name;
string WinUserName = WindowsIdentity.GetCurrent().Name;
UserName.InnerText = EUserName;
}
}
Also add references
**microsoft.crm.sdk.proxy**
**microsoft.xrm.sdk**
Related
Our IT department gave me credentials for an FTPS, which I can access using FileZilla
But I also need to access the FTPS using an application I am working on to automate the process. The information provided to me was,
That this is an FTP over TLS/SSL
IP: xxx.xxx.xx.xx
Port: 990 <-- suggesting its an implicit encryption
UserName: username.ftp
Password: password123
After reading some posts on WinSCP on stack and their documentation, I still can't access the ftps using my application. My code so far..
SessionOptions sessionOp = new SessionOptions()
{
FtpSecure = FtpSecure.Implicit,
Protocol = Protocol.Ftp,
HostName = IP,
UserName = userName,
Password = password,
};
sessionOp.AddRawSettings("ProxyMethod", "3");
sessionOp.AddRawSettings("ProxyPort", "990");
using (Session session = new Session())
{
session.Open(sessionOp);
var list = session.ListDirectory(dir);
Console.WriteLine(list);
}
The error I get is, "Failed to Connect" from WinSCP
How can I access this FTPS?
What you did is configuring the HTTP Proxy port to 990. Instead you should configure the FTPS port.
SessionOptions sessionOp = new SessionOptions()
{
FtpSecure = FtpSecure.Implicit,
Protocol = Protocol.Ftp,
HostName = IP,
UserName = userName,
Password = password,
PortNumber = 990
};
and remove the lines
sessionOp.AddRawSettings("ProxyMethod", "3");
sessionOp.AddRawSettings("ProxyPort", "990");
Also, I suggest using the WinSCP GUI to try this instead of FileZilla, considering that the library is related to the GUI.
I am using the code below to connect to DocuSign API.
WHAT AM I doing wrong, I keep getting Username and Password not correct when they are!
String auth = "<DocuSignCredentials><Username>john.connolly#lechase.com</Username><Password>password</Password><IntegratorKey>20be051c-4c25-46c1-b0f1-1f10575a2e40</IntegratorKey></DocuSignCredentials>";
DSAPIServiceSoapClient client = new DSAPIServiceSoapClient("DSAPIServiceSoap");
using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope(client.InnerChannel))
{
System.ServiceModel.Channels.HttpRequestMessageProperty httpRequestProperty = new System.ServiceModel.Channels.HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-DocuSign-Authentication", auth);
System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = httpRequestProperty;
EnvelopeStatus status = client.RequestStatusEx("12d46951-1f1c-48cd-9a28-e51685d67ccd");
Console.Out.WriteLine("Subject: " + status.Subject);
}
Since you use the (Legacy Header Authentication uses the X-DocuSign-Authentication header):
Use the Authentication: login method
to retrieve the account number and the baseUrl for the account.
The url for the login method is www.docusign.net for production and
demo.docusign.net for the developer sandbox. The baseUrl field is
part of the loginAccount object. See the docs and the loginAccount
object
The baseUrl for the selected account, in production, will start with na1, na2, na3, eu1, or something else. Use the baseUrl that is
returned to create the basePath (see the next step.) Use the
basePath for all of your subsequent API calls.
As returned by login method, the baseUrl includes the API version and account id. Split the string to obtain the basePath, just the
server name and api name. Eg, you will receive
https://na1.docusign.net/restapi/v2/accounts/123123123. You want
just https://na1.docusign.net/restapi
Instantiate the SDK using the basePath. Eg ApiClient apiClient = new ApiClient(basePath);
Set the authentication header as shown in the examples by using Configuration.Default.AddDefaultHeader Ref.
Sample Code: Try a verbatim string for your auth string.
string auth = #"<DocuSignCredentials>
<Username>john.connolly#lechase.com</Username>
<Password>S3cre+p455w0Rd</Password>
<IntegratorKey>20be051c-4c25-46c1-b0f1-1f10575a2e40</IntegratorKey>
</DocuSignCredentials>";
DSAPIServiceSoapClient apiService = new DSAPIServiceSoapClient();
using (var scope = new System.ServiceModel.OperationContextScope(apiService.InnerChannel))
{
var httpRequestProperty = new System.ServiceModel.Channels.HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-DocuSign-Authentication", auth);
System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = httpRequestProperty;
EnvelopeStatus envStatus = apiService.CreateAndSendEnvelope(envelope);
return envStatus.EnvelopeID;
}
I have a VM powered on and running in azure. I know its name but want to retrieve its IP address programmatically using the new C# SDK and avoiding the REST API. How can I do this?
Try this:
string subId = "deadbeef-beef-beef-beef-beefbeefbeef";
string resourceGroup = "SORG01";
string vmName = "SORG01-BOX01";
using (var client = new ComputeManagementClient(credentials))
{
client.SubscriptionId = subId;
VirtualMachine vm = VirtualMachinesOperationsExtensions.Get(client.VirtualMachines, resourceGroup, vmName);
networkName = vm.NetworkProfile.NetworkInterfaces[0].Id.Split('/').Last();
}
using (var client = new NetworkManagementClient(credentials))
{
client.SubscriptionId = subId;
var network = NetworkInterfacesOperationsExtensions.Get(client.NetworkInterfaces, resourceGroup, vmName);
string ip = network.IpConfigurations[0].PrivateIPAddress;
}
To have these classes, you'll need to install from nuget:
Microsoft.Azure.Management.Compute
Microsoft.Azure.Management.Compute.Models
Microsoft.Azure.Management.Network
Note that you'll have to select "Include Prerelease" on the nuget search window in order to find these packages. credentials is a Microsoft.Rest.TokenCredentials object that you acquire in this manner:
var authContext = new AuthenticationContext("https://login.windows.net/{YourTenantId}");
var credential = new ClientCredential("{YourAppID}", "{YourAppSecret}");
var result = authContext.AcquireTokenAsync("https://management.core.windows.net/", credential);
result.Wait();
if (result.Result == null)
throw new AuthenticationException("Failed to obtain the JWT token");
credentials = new TokenCredentials(result.Result.AccessToken);
The easiest way to retrieve the public IP Address of Azure Virtual Machine is
{_VirtualMachineInstance}.GetPrimaryPublicIPAddress().IPAddress;
Very good explanation of this matter you can find here- Tom Sun answer:
Get Azure VM using resource manager deployment and rest api
I want to collect a List of Project in TFS 2013 Using API .
I am Putting URL and User name and Password, (Server properly Connected Browser).
I have collected all Project with TFS Collection List. But my API Call does not working on client. What is the problem?
Here My Sample Code
Uri configurationServerUri = new Uri(URL);
NetworkCredential credentials = new NetworkCredential(UserName, Password);
teamProjectCollection = new TfsTeamProjectCollection(configurationServerUri, credentials);// Set Connection
teamProjectCollection.EnsureAuthenticated();
//CatalogNode configurationServerNode = teamProjectCollection.TeamFoundationServer.TfsTeamProjectCollection.CatalogNode;
//li.Add(configurationServerNode.Resource.DisplayName);
TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(configurationServerUri);
ITeamProjectCollectionService tpcService = configurationServer.GetService<ITeamProjectCollectionService>();
foreach (TeamProjectCollection tpc in tpcService.GetCollections())
{
list.Add(tpc.Name);
}
I'm a total newbie to this
Trying to connect to an ldap server with PrincipalContext. I have tried all solutions on this site to no avail.
Things I've tried:
PrincipalContext insPrincipalContext =
new PrincipalContext(ContextType.Domain);
PrincipalContext insPrincipalContext =
new PrincipalContext(ContextType.Domain, "ldap://localhost:389/dc=maxcrc,dc=com");
PrincipalContext insPrincipalContext =
new PrincipalContext(ContextType.Domain, "maxcrc.com");
All give the same result:
LDAP server not available
Only ContextType.Machine works basically.
Not sure if my LDAP server is set up correctly:
Host: localhost
Port: 389
Base DN: dc=maxcrc,dc=com
URL: ldap://localhost:389/dc=maxcrc,dc=com
Testing with Softerra LDAP Browser
Any tutorials from start to finish will be much appreciated...
I have been facing the same issue and I found a solution.
I'm able to connect easily using following code:
ADUser_Id = "domainName\\username"; //make sure user name has domain name.
Password = "xxxx";
var context = new PrincipalContext(ContextType.Domain,"server_address", ADUser_Id,Password);
/* server_address = "192.168.15.36"; //don't include ldap in url */
I had similar issues. It turned out that I had to pass username and password in the object initialization. Please try using a statement like below:
PrincipalContext insPrincipalContext =
new PrincipalContext(ContextType.Domain,
"ldap://localhost:389/dc=maxcrc,dc=com",
userName,
password);
Also make sure that your username has domain in it.
For example,
userName = "mydomainname" + "\\" + "john_jacobs"
Use the following constructor overload for PrincipalContext:
public PrincipalContext(
ContextType contextType,
string name,
string container
)
And separate the server name from the LDAP string:
PrincipalContext insPrincipalContext =
new PrincipalContext(ContextType.Domain, "localhost:389", "dc=maxcrc,dc=com");
https://msdn.microsoft.com/en-us/library/bb348316%28v=vs.110%29.aspx
In my environment I had to create the principal context with just the domain controller host name, and then separately validate the user credentials.
string domainControllerName = "PDC";
string domainName = "MyDomain"; // leave out the .Local, this is just to use as the prefix for the username if the user left it off or didn't use the principal address notation
string username = "TestUser";
string password = "password";
using (var ldap = new PrincipalContext(ContextType.Domain, domainControllerName))
{
var usernameToValidate = username;
if (!usernameToValidate.Any(c => c == '#' || c == '\\'))
usernameToValidate = $"{domainName}\\{username}";
if (!ldap.ValidateCredentials(username, context.Password, ContextOptions.SimpleBind))
throw new UnauthorizedException();
}
This example allows for all three of these variations to the username to validate:
TestUser
MyDomain\TestUser
TestUser#MyDomain.Local
You may want to try your local machine address instead :
ldap://127.0.0.1:389/dc=maxcrc,dc=com
If that doesn't work, I'd fire up Wireshark, and have it capture traffic on port 389 as you're attempting to connect via Softerra.
In my time working with LDAP and .Net DirectoryServices, that error usually means the syntax or naming convention of the path is incorrect, or does not point to a valid directory end point.
That error might be due to trying to connect as "Anonymous" without specifying it explicitly.
By default all connections are Negotiable. So if you try something like that you could try the following:
LdapDirectoryIdentifier ldap = new LdapDirectoryIdentifier("My Hostname or IP Address",10389); //10389 might be your non default port
LdapConnection connection = new LdapConnection(ldap);
connection.AuthType = AuthType.Anonymous;