How do I resolve a OpenPop.Net Authenticate Exception - c#

I am using OpenPop.Net to connect to a GoDaddy hosted email account in a C# application. The Authenticate() method throws an exception with the error message of "The stream used to retrieve responses from was closed". I doubled checked that the POPServer, POPPort, POPUserName, and POPPassword values were valid using Outlook 2007.
using (Pop3Client pop3 = new Pop3Client())
{
pop3.Connect(POPServer, POPPort, false);
pop3.Authenticate(POPUserName, POPPassword);
Int32 messageCount = pop3.GetMessageCount();
}

The Authenticate() method supports a 3rd parameter, an enumeration called AuthenticationMethod. According to the help file, if the 3rd parameter is not passed the Authenticate() method defaults to an authentication method of Auto. The help file goes on to say that the Auto method is the recommended method to authenticate with. If Apop is supported by the server, Apop is used for authentication. If Apop is not supported, Auto will fall back to UsernameAndPassword authentication.
I tried explicitly passing Auto, and the Authenticate() method failed with the same error. I then tried explicitly passing UsernameAndPassword, this time it worked. I'm not sure if this is a bug in OpenPop.Net or a problem with the POP server. Here is the working code.
using (Pop3Client pop3 = new Pop3Client())
{
pop3.Connect(POPServer, POPPort, false);
pop3.Authenticate(POPUserName, POPPassword, AuthenticationMethod.UsernameAndPassword);
Int32 messageCount = pop3.GetMessageCount();
}

Related

Unable to get new token using JWT method (C#)

I am trying to set up a method so each time my application is accessed it retrieves a new token using JWT.
I've ran through the docusign github examples but this is still newer to me so I am stuck unfortunately.
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using DocuSign.eSign.Client.Auth;
public string getAccessToken(){
var apiClient = new ApiClient();
OAuth.OAuthToken authToken = apiClient.RequestJWTUserToken({clientID},
"{Impersonated User GUID}",
"https://account-d.docusign.com",
Encoding.UTF8.GetBytes(System.Configuration.ConfigurationManager.AppSettings["jwtPrivKey"]),
1);
return authToken.access_token;
}
Exception Details: DocuSign.eSign.Client.ApiException: Error while requesting server, received a non successful HTTP code Error with response Body:
I have similar code to what you have. I ran into an issue when I was developing where my auth path variable could not include "https://". I have to use plain "account-d.docusign.com" instead.

TFS WebHook fails after Webapi is published to IIS

I'm using TFS 2015 Webhook to be notified when a checkin occurs. I've created an API using .NET 4.6 so I can receive the notifications. It works perfectly when I use Visual Studio 2015 to load the API, but once I publish it to IIS 7, TFS starts to show Status Code: 500, even if the code is executed without any exception.
Here is the method from the Web Api. I'm writing an output to log, to make sure it is executed. It writes "returning success" every time.
public HttpResponseMessage Post([FromBody]Models.Content value)
{
try
{
IndexUpdater iUpdater = new IndexUpdater();
iUpdater.UpdateIndex(value.resource.changesetId);
using (StreamWriter w = File.AppendText("C:\\publish\\TFSListenerAPI\\log.txt"))
{
w.WriteLine("returning success");
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch(Exception ex)
{
using (StreamWriter w = File.AppendText("C:\\publish\\TFSListenerAPI\\log.txt"))
{
w.WriteLine("erro");
w.WriteLine(ex.Message);
}
}
}
Here is the returned message
Here is the return when I execute the API using Visual Studio, same code.
Edit: Just found out that the error 500 happens only when the below method is executed. The weird part is the fact that the code works, and the content is
returned with success.
private string GetFileContent(string tfsPath)
{
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://tfs2015.com.br:8080/tfs/cd-jv"), new System.Net.NetworkCredential("user", "password"));
server.Authenticate();
VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;
Microsoft.TeamFoundation.VersionControl.Client.Item item = version.GetItem(tfsPath);
string tempFileName = System.IO.Path.GetTempFileName();
item.DownloadFile(tempFileName);
var content = File.ReadAllText(tempFileName, Encoding.GetEncoding("ISO-8859-1"));
return content;
}
So, as I edit the post after posting it, the problem is in this line:
TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("http://tfs2015.com.br:8080/tfs/cd-jv"), new System.Net.NetworkCredential("user", "password"));
For some reason, if this request is made before the API returns OK to the Webhook, the Webhook shows the error 500. So the way I found to make it work was by making sure this line is executed only after tue API returns OK. It can be done by using Async/Await and Thread.Sleep().
According to the error message Status Code: 500 it should be internal server error, something strange and unusual happened that was likely not your fault at all.
Try to check the event viewer, if there are any other logs with HResult codes when you encounter 500 error on an Internet Information Services (IIS) 7.0. Then refer to below article for further trouble shooting:
HTTP Error 500.0 – Internal Server Error" error when you you open an IIS 7.0 Webpage
Also check if this thread helps for you : How do I receive a custom webhook in an IIS hosted website?

ListTweetOnUserTimeline returns null

I'm using TweetSharp for C#, and I'm successfully able to publish tweets to twitter via this.
However, I'm trying to read the most recent tweets from the account's timeline, but I keep getting null back every time I try to get the data. The following code returns null
string consumerKey = <consumerKey>;
string consumerSecret = <consumerSecret>;
TwitterService service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(consumerKey, consumerSecret);
var options = new ListTweetsOnUserTimelineOptions()
{
ScreenName = screenName,
SinceId = 0,
Count = 5
};
var currentTweets = service.ListTweetsOnUserTimeline(options);
I've tried using UserId instead of ScreenName, but I still get null as a result fir currentTweets. All the examples I can find are pointing to this method, but it doesn't work.
Any Ideas?
If you're using an older version of .NET, then you may be using TLS 1.1 under the hood to communicate with Twitter. If you are doing this, then the AuthenticateWith will fail silently, and nothing will work.
You need to add the code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
In order to make this work.
Also you should be passing the accessToken and accessTokenSecret to AuthenticateWith, not the consumer keys, as mentioned above.
I think your problem is the AuthenticateWith call. You appear to be passing the consumer token and secret again, but the AuthenticateWith overload that takes only two arguments expects a user token and secret. I suspect you are therefore getting an unauthorised response (not sure why you don't get an error).
I would suggest either removing the AuthenticateWith call (you've already provided the consumer token in the constructor), or changing it so you pass details for a valid user token instead of the consumer one.
You could also check the Response property on the twitter service after your call completes, and inspect the http status code/reason phrase/content etc. to see if that gives you more detail about what is going wrong.

PayPal SOAP API - Express Checkout - Error 10002

I'm trying to connect my website to the Paypal Sandbox in order to use the Express Checkout feature. I've used this link as reference but i keep getting the 10002 Error "Security header is not valid".
From the documentation this has to be a invalid credentials problem but if i made the request manually through soapUI it returns "Sucess", if i use the curl command it also works as expected.
Scenario: ASP.NET page with two Web References one to https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl and another to https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl, the given credentials are Username, Password and Signature as you can see in the following code snippet:
using CloudShop.com.paypal.sandbox.www;
namespace CloudShop
{
public static PayPalAPIAASoapBinding BuildPayPalWebservice()
{
UserIdPasswordType credentials = new UserIdPasswordType()
{
Username = CloudShopConf.PayPalAPIUsername,
Password = CloudShopConf.PayPalAPIPassword,
Signature = CloudShopConf.PayPalAPISignature
};
PayPalAPIAASoapBinding paypal = new PayPalAPIAASoapBinding();
paypal.RequesterCredentials = new CustomSecurityHeaderType()
{
Credentials = credentials
};
return paypal;
}
Right now i would like to know how to proceed with the debug. What could be wrong?
Some ideas:
Check if you are using the Live-Credentials for the sandbox account.
Are you using https://api-3t.sandbox.paypal.com/2.0/ (especially the -3t part) as the endpoint? You should as you are using Signature authentication.
As usual, you should step through every setting you are using: protocol, API Endpoint, Version, Credentials etc. and compare you're manual SoapUI call with the information stored in you shop configuration.
I also found a blog article on this error that might help resolving this issue.

Cannot send Email in custom workflow sharepoint 2010

I have some trouble when using SPUtility.SendEmail method in a custom workflow.
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
if (SPUtility.IsEmailServerSet(workflowProperties.Site.OpenWeb()))
{
StringDictionary headers = new StringDictionary();
headers.Add("to", "myemailaddress#mailinator.com");
headers.Add("from", "somebody#example.com");
headers.Add("content-type", "text/html");
SPSecurity.RunWithElevatedPrivileges(delegate()
{
bool test = SPUtility.SendEmail(web, headers, "some message body");
});
}
}
in the code's above, the method SPUtility.SendEmail always returning false.
I've even tried to use RunWithElevatedPrivileges, but still the method returns false.
The smtp configuration is not the problem, because the standard email notification when a task is assigned in sharepoint is sent all right.
The strange part is, I have tried this SendEmail method using a timer job, and the method is working perfectly fine.
please somebody help me if there is something i need to add to my method's above.
thanks.
Try to get the web reference in the elevated privileges scope.
I couldn't find the root of this problem.
I decided to do create 2 workflow: the first is to send the email using initiation parameter (build using sharepoint designer). the second one is workflow that initiate the first workflow.
it's now up and running.

Categories

Resources