crm 4.0 crmservice how to connect remote server? - dynamics-crm

I'm trying to connect to the server crm in this way:
CrmService crmService = new CrmService();
crmService.PreAuthenticate = true;
Shareremover.CrmSdk.CrmAuthenticationToken token = new CrmSdk.CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = Shareremover.Properties.Settings.Default.organization;
crmService.CrmAuthenticationTokenValue = token;
crmService.Url = http : //bfitcrm/MSCrmServices/2007/CrmService.asmx
//crmService.UnsafeAuthenticatedConnectionSharing = true;
if(String.Empty != Shareremover.Properties.Settings.Default.login.Trim() && String.Empty != Shareremover.Properties.Settings.Default.password.Trim() && String.Empty != Shareremover.Properties.Settings.Default.domain.Trim())
{
crmService.Credentials = new System.Net.NetworkCredential(Shareremover.Properties.Settings.Default.login,Shareremover.Properties.Settings.Default.password,Shareremover.Properties.Settings.Default.domain);
crmService.Execute(Rrequest);
}
else
{
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
in the line
crmService.Execute(Rrequest);
I have the following error:
The request failed with HTTP status 401: Unauthorized.

Related

Calling an Oracle GlInterface SOAP service in .net Core

Error : System.ServiceModel.FaultException`1[Service.ServiceErrorMessage]: JBO-GL:::GL_INVALID_LEDGER: GL-781535You have entered an invalid ledger value. (Fault Detail is equal to Service.ServiceErrorMessage).
only result when I search
BasicHttpBinding basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress endpointAddress = new EndpointAddress(new Uri("https://fa-eosd-dev1-saasfaprod1.fa.ocs.oraclecloud.com:443/fscmService/JournalImportService?WSDL"));
ChannelFactory<JournalImportService> factory = new ChannelFactory<JournalImportService>(basicHttpBinding, endpointAddress);
factory.Credentials.UserName.UserName = "user";
factory.Credentials.UserName.Password = "pass";
JournalImportService serviceProxy = factory.CreateChannel();
((ICommunicationObject)serviceProxy).Open();
var opContext = new OperationContext((IClientChannel)serviceProxy);
var prevOpContext = OperationContext.Current; // Optional if there's no way this might already be set
OperationContext.Current = opContext;
importJournalsRequest importJournalsRequest = new importJournalsRequest();
GlInterfaceTransHeader glInterfaceTransHeader = new GlInterfaceTransHeader();
glInterfaceTransHeader.LedgerId = 300000001958365;
List<GlInterface> glInterface = new List<GlInterface>();
glInterface.Add(glInter);
glInterfaceTransHeader.GlInterface = glInterface.ToArray();
importJournalsRequest.interfaceRows = glInterfaceTransHeader;
try
{
var result = await serviceProxy.importJournalsAsync(importJournalsRequest);
//cleanup
factory.Close();
((ICommunicationObject)serviceProxy).Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
// *** ENSURE CLEANUP *** \\
CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
OperationContext.Current = prevOpContext; // Or set to null if you didn't capture the previous context
}
}
glInterfaceTransHeader.AccountingDateSpecified = true;

Asp.net Web API returning null response

am faced with a challenge for some time now. I have a web service (asp.net web api), that consumes a certain api, after the consumption, my api will then send the consumed data to another external api. I use REST Sharp for my data serialization and request.
But anytime i send this request. I get a null result.
Anybody to help?
Sequel to my question above #igor, below is my code snippet
public object AccountOpening(JObject exRequest)
{
var Account = new AccountViewModel(exRequest.ToString());
Account.cifID = "null";
Account.AddrCategory = "Mailing";
Account.Country = "NG";
Account.HoldMailFlag = "N";
Account.PrefAddr = "Y";
Account.Language = "UK (English)";
Account.IsMinor = "N";
Account.IsCustNRE = "N";
Account.DefaultAddrType = "Mailing";
Account.Occupation = "OTH";
Account.PhoneEmailType = "CELLPH";
var serviceAPI = ConfigurationManager.AppSettings["RemoteAPI"];
var request = new RestSharp.Serializers.Newtonsoft.Json.RestRequest();
request.AddParameter("application/json", Account, ParameterType.RequestBody);
request.RequestFormat = DataFormat.Json;
request.Method = Method.POST;
request.JsonSerializer = new RestSharp.Serializers.JsonSerializer();
var client = new RestClient(serviceAPI);
IRestResponse resp = client.Post(request);
if (resp.IsSuccessful==true)
{
return Json(new {resp.Content });
}
}

How to get YouTube channel name and URL after authenticating

Once I have authenticated a user - such as in the code below - how can I find out their channel name and URL of channel?
I'm using the YouTube data api v3 with .NET library:
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.YoutubeReadonly },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.GetType().ToString()
});
Finally worked out how to do it. Once you get the token back from the authentication do this:
var channelsListRequest = _youTubeService.Channels.List("id,snippet");
channelsListRequest.Mine = true;
var channelsListResponse = channelsListRequest.Execute();
if ( (null != channelsListResponse) &&
(null != channelsListResponse.Items) &&
(channelsListResponse.Items.Count > 0) )
{
Channel userChannel = channelsListResponse.Items[0];
string youtubeUserID = userChannel.Id;
string ytChannelURL = "https://www.youtube.com/channel/" + userChannel.Id;
string name = userChannel.Snippet.Title;
}
Phew!

C# - WebRequestMethods.Ftp.DownloadFile not working (timeout)

Good afternoon everyone.
I'm trying to download a few files from a FTP server and I don't know why this isn't working, because the same code worked before. Now when i run the service I get the following error:
Error 1053: The service did not respond to the start or control request in a timely fashion
I've tried doing other Methods like GetFileSize or even the DeleteFile that it's suppose to execute after the DownloadFile and they work, but this one isn't and i can't figure out why. Any ideas? My code is below, many thanks!
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(server + file));
reqFTP.Credentials = new NetworkCredential(username, password);
reqFTP.KeepAlive = true;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
reqFTP.Timeout = -1;
FtpWebResponse response2 = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream2 = response2.GetResponseStream();
FileStream writeStream = new FileStream(folder + file, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream2.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream2.Read(buffer, 0, Length);
}
writeStream.Close();
response2.Close();
try
{
string uri2 = server + file;
Uri serverUri2 = new Uri(uri);
if (serverUri2.Scheme != Uri.UriSchemeFtp)
{
return;
}
FtpWebRequest reqFTP2;
reqFTP2 = (FtpWebRequest)FtpWebRequest.Create(new Uri(server + file));
reqFTP2.Credentials = new NetworkCredential(username, password);
reqFTP2.KeepAlive = false;
reqFTP2.Method = WebRequestMethods.Ftp.DeleteFile;
reqFTP2.UseBinary = true;
reqFTP2.Proxy = null;
reqFTP2.UsePassive = false;
FtpWebResponse response3 = (FtpWebResponse)reqFTP2.GetResponse();
Stream responseStream3 = response3.GetResponseStream();
response3.Close();
}

ASP.NET MVC 3 - Certificates - Configuration Error

I have an ASP.NET MVC 3 application that relies on the user of certificates. When I run the application, I receive an error that says:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: ID1024: The configuration property value is not valid.
Property name: 'serviceCertificate'
Error: 'ID1001: The certificate does not have an associated private key.
Thumbprint: '[ID]''
Source Error:
Line 278:
Line 279: <microsoft.identityModel>
Line 280: <service>
Line 281: <audienceUris>
Line 282: <!--<environment name="DEV">-->
ID is actually a full-blown thumbprint. What am I doing wrong? How do I fix this? I suspect that my certificate is not setup properly. However, I'm not sure if this is true, or how to even check. Thank you!
I was able to resolve this issue by doing the following Hope this helps.
public static System.Security.Cryptography.X509Certificates.StoreName StoreName
{
get
{
StoreName storeName = StoreName.My;
if (WebConfigurationManager.AppSettings[SigningStoreName] != null)
storeName = (StoreName)Enum.Parse(typeof(StoreName), WebConfigurationManager.AppSettings[SigningStoreName]);
return storeName;
}
}
public static System.Security.Cryptography.X509Certificates.StoreLocation StoreLocation
{
get
{
StoreLocation storeLocation = StoreLocation.CurrentUser;
if (WebConfigurationManager.AppSettings[SigningStoreLocation] != null)
storeLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), WebConfigurationManager.AppSettings[SigningStoreLocation]);
return storeLocation;
}
}
public static SigningCredentials GetSigningCredentials()
{
X509Certificate2 cert = CertificateUtil.GetCertificate(StoreName, StoreLocation, WebConfigurationManager.AppSettings[Common.SigningSubjectNameOrThumbprint]);
string signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
, digestAlgorithm = "http://www.w3.org/2000/09/xmldsig#sha1";
RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider;
if (rsa == null) rsa = RSA.Create() as RSACryptoServiceProvider;
RsaSecurityKey rsaKey = new RsaSecurityKey(rsa);
RsaKeyIdentifierClause rsaClause = new RsaKeyIdentifierClause(rsa);
SecurityKeyIdentifier signingSki = new SecurityKeyIdentifier(new SecurityKeyIdentifierClause[] { rsaClause });
SigningCredentials signingCredentials = new SigningCredentials(rsaKey, signatureAlgorithm, digestAlgorithm, signingSki);
return signingCredentials;
}
public static X509Certificate2 GetCertificate(StoreName name, StoreLocation location, string subjectNameOrThumbprint)
{
X509Store store = new X509Store(name, location);
X509Certificate2Collection certificates = null;
store.Open(OpenFlags.ReadOnly);
try
{
X509Certificate2 result = null;
certificates = store.Certificates;
if (certificates != null && certificates.Count > 0)
{
result = (from X509Certificate2 cert in certificates
where !string.IsNullOrWhiteSpace(cert.Thumbprint)
&& cert.Thumbprint.ToLower().Replace(" ", "") == subjectNameOrThumbprint.ToLower().Replace(" ", "")
select cert
).FirstOrDefault();
if (result == null)
result = (from X509Certificate2 cert in certificates
where cert.SubjectName != null
&& cert.SubjectName.Name.ToLower().Replace(" ", "") == subjectNameOrThumbprint.ToLower().Replace(" ", "")
select cert
).FirstOrDefault();
}
string errMsg = string.Format("{0} - {1} in {2}", name.ToString(), subjectNameOrThumbprint, location.ToString());
if (result == null)
throw new ApplicationException(string.Format("No certificate was found for {0} ", errMsg));
else if (result.Verify() == false)
throw new ApplicationException(string.Format("Unable to verify certificate for {0}", errMsg));
return result;
}
finally
{
store.Close();
}
}

Resources