im trying to read email from exchange server using the below script :
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ProhibitDtd = false;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CertificateValidationCallBack);
service.Credentials = new WebCredentials("user", "password" , "domain");
service.UseDefaultCredentials = true;
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.Url = new Uri("https://IP/");
Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
Label1.Text = inbox.DisplayName.ToString();`
but im getting this error :
DTD is prohibited in this XML document.
i try this solution :
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ProhibitDtd = false;
but error stil there .
XmlReaderSettings xrs = new XmlReaderSettings()
xrs.DtdProcessing = DtdProcessing.Parse;
Documented at: https://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.dtdprocessing(v=vs.110).aspx
Related
I was try to connect my TFS server using my credentials . But i am getting error 'Basic authentication requires a secure connection to the server.'
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
TfsClientCredentials tfsClientCredentials = new TfsClientCredentials(basicAuthCredential)
{
AllowInteractive = false
};
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), tfsClientCredentials);
tfs.EnsureAuthenticated();
My tfs didn't have the https. Any alternative to fix it But browser level it is working fine
The BasicAuthCredential requires https://, I believe, and I wasn't able to access my TFS with https://. So I found another way to get from NetworkCredential to VssCredentials.
string username = "adminuser";
string pwd = "mypassword";
string domain = "http://localhost:8080/tfs/defaultcollection";
NetworkCredential networkCredential = new NetworkCredential(username, pwd);
//BasicAuthCredential basicAuthCredential = new BasicAuthCredential(networkCredential);
Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(networkCredential);
VssCredentials vssCred = new VssClientCredentials(winCred);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(domain), vssCred);
tfs.EnsureAuthenticated();
Try using the following code:
String collectionUri = "http://localhost:8080/tfs/defaultcollection";
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
below Useexchangeservice method used for connect mail server and getting mail from server but its showing error like "Connection did not succeed. Try again later".
static void UseExchangeService()
{
string userEmailAddress = "xyz2#domain.com";
string userPassword = "testnew#123";
ExchangeService service = new
ExchangeService(ExchangeVersion.Exchange2010_SP2);
#region Authentication
service.UseDefaultCredentials = true;
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
var folder = new FolderId(WellKnownFolderName.Calendar, new Mailbox(userEmailAddress));
#endregion
#region Endpoint management
service.AutodiscoverUrl(userEmailAddress,
RedirectionUrlValidationCallback);
#endregion
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("Lalit.Sharma2#securemeters.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("Sent by using the EWS Managed API");
email.Save(new FolderId(WellKnownFolderName.Drafts, "Lalit.Sharma2#securemeters.com"));
email.Send();
}
I am trying to connect online TFS using WCF service but it is throwing me exception "TF30063: You are not authorized to access https://abdul-r.visualstudio.com/DefaultCollection/TestTFS.".
Below is my sample code
NetworkCredential netCred = new NetworkCredential(
"*MyEmail*",
"*MyPassword*");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials credential = new TfsClientCredentials(basicCred);
credential.AllowInteractive = false;
string TFSServerPath = "https://abdul-r.visualstudio.com/DefaultCollection/TestTFS";
using (TfsTeamProjectCollection tfs1 = new TfsTeamProjectCollection(new Uri(TFSServerPath), credential))
{
tfs1.EnsureAuthenticated();
}
Any help would be appreciated.
I have local tfs 2012. On Visual studio 2012 , use c# , I write program which programmatically connect to tfs server. But I have error:
{"TF30063: You are not authorized to access http://server:8080/tfs."} System.Exception {Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException}
My code:
Uri collectionUri = new Uri("http://server:8080/tfs");
NetworkCredential netCred = new NetworkCredential("login","password");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred);
teamProjectCollection.EnsureAuthenticated();//throw error here
Can you help me fix this error?
P.S. I try do connect this way, but I have same error:
var projectCollection = new TfsTeamProjectCollection(
new Uri("http://myserver:8080/tfs/DefaultCollection"),
new NetworkCredential("youruser", "yourpassword"));
projectCollection.Connect(ConnectOptions.IncludeServices);
And this way:
Uri collectionUri = new Uri("http://server:8080/tfs/DefaultCollection");
NetworkCredential netCred = new NetworkCredential("login","password","Server.local");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred);
teamProjectCollection.EnsureAuthenticated();
Hope it helps you.
var tfsCon = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://server:8080/tfs"));
tfsCon.Authenticate();
var workItems = new WorkItemStore(tfsCon);
var projectsList = (from Project p in workItems.Projects select p.Name).ToList();
or
Uri TfsURL = new Uri(""http://server:8080/tfs"");
NetworkCredential credential = new NetworkCredential(Username, Password, Domain);
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(TfsURL, credential);
collection.EnsureAuthenticated();
If fails here you need to configure in App.config to set the default proxy:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
</system.net>
</configuration>
I know that this error is very common, but I tried to apply the solutions to this problem and could not solve it.
Thats my code:
var endpoint = new EndpointAddress(new Uri("http://www3prz.bancobonsucesso.com.br/Servicos/app.svc"), EndpointIdentity.CreateDnsIdentity("bancobonsucesso.com.br"));
var binding = new WSHttpBinding();
binding.UseDefaultWebProxy = true;
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.EstablishSecurityContext = true;
binding.Security.Message.NegotiateServiceCredential = true;
var customBinding = new CustomBinding(binding);
SymmetricSecurityBindingElement security = customBinding.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
security.LocalClientSettings.DetectReplays = false;
SecureConversationSecurityTokenParameters secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
SecurityBindingElement bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
bootstrap.LocalClientSettings.DetectReplays = false;
ws = new ServicoClient(customBinding, endpoint);
ws.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ws.ClientCredentials.UserName.UserName = "test";
ws.ClientCredentials.UserName.Password = "test";
var return = ws.EmitirBoleto("test");
IN the WCF Binding use useDefaultWebProxy:
<bindings>
<basicHttpBinding>
<binding name="bindingName" useDefaultWebProxy="true">
WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = wproxy;
This error may arise problem with proxy settings.
Please check Proxy setting with your web browser. Just changed connection settings Option -> settings -> connection settings to Auto detect proxy settings
Good luck ...