Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException Trying to Read Email From EWS C# - c#

I'm Developing a Console Application for testing purpose in C#. This Application is made to read the Email from MS Exchange Web Service server2007. But I can't get it working for a while. should I include some code in the App.config? which one!
here is this exception
AutodiscoverLovalException
Even I make use of configurattion.appSettings() to pass the key and the value, Still getting the same handler. this really frustrate a lot.
Here is my tested code:
static void Main(string[] args)
{
// Create the binding.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user", "pass", "domain");
// Set the URL.
service.AutodiscoverUrl("user#domain.com",);
}
static bool RedirectionCallback(string url)
{
return url.ToLower().StartsWith("https://");
}
Anyone have an idea?

In your given code, you do not call the method RedirectionCallback.
Edit line 8 to the following:
service.AutodiscoverUrl("user#domain.com", RedirectionCallback);

Related

TwitchLib Help- Work around old TwitchClient() method

I was watching a tutorial on how to script a bot using C# and the instructor used (to my knowledge) an old call to TwitchClient which takes credentials and references. However, it is currently not the case and I'm wondering now what might be a good way to work around it. Currently, the method takes a websocket and logger but I have suspicion that you still need to use credentials and references.
Any help will be appreciated.
Here's the video with the timestamp: https://youtu.be/5f1T9hQqJps?t=8m3s
Instead of the single line in the video, these two lines should now achieve mostly the same effect:
client = new TwitchClient();
client.Initialize(credentials, "channel");
If you want to also enable logging (like in the video), then you will need to provide an instance of ILogger to the first call like so:
client = new TwitchClient(null, myLoggingInstance);
The WebSocket parameter is used for testing (so you can generate your own traffic to test your bot), the docs advise not to set this.
its quite simple actually, even the github page shows a simple example:
ConnectionCredentials credentials = new ConnectionCredentials("twitch_username", "access_token");
var clientOptions = new ClientOptions
{
MessagesAllowedInPeriod = 750,
ThrottlingPeriod = TimeSpan.FromSeconds(30)
};
WebSocketClient customClient = new WebSocketClient(clientOptions);
client = new TwitchClient(customClient);
client.Initialize(credentials, "channel");
client.OnLog += Client_OnLog;
client.Connect();
then later declare this function:
private void Client_OnLog(object sender, OnLogArgs e)
{
Console.WriteLine($"{e.DateTime.ToString()}: {e.BotUsername} - {e.Data}");
}

Instasharp in a Console Application

I have a .net console application that I want to use to pull Instagram posts via the Instasharp wrapper using a hashtag search.
I use C# .net web forms extensively and am not very familiar with MVC nor how to use the await keyword. The code sample below seems to run, but never provides any output.
This line:
var tagInfo = await tagApi.Get("soccer");
Returns me to the calling method with no indication of retrieved data.
Can anyone provide insights as to what I am doing wrong here?
public static async void GetInstagram(String tag, InstagramConfig config)
{
var instagramPosts = await LoadInstagramPosts(tag, config);
dynamic dyn = JsonConvert.DeserializeObject(instagramPosts.ToString());
foreach (var data in dyn.data)
{
Console.WriteLine("{0} - {1}", data.filter, data.images.standard_resolution.url);
}
}
public static async Task<TagResponse> LoadInstagramPosts(String hashTagTerm, InstagramConfig config)
{
var tagApi = new InstaSharp.Endpoints.Tags(config);
var tagInfo = await tagApi.Get("soccer");
}
EDITED code after first comment which solved my initial problem.
I feel like I'm close but something is still missing.
See specific questions below...
I've based the code on the documentation from InstaSharp GitHub (https://github.com/InstaSharp/InstaSharp). GitHubs example is based on an MVC application, mine is not an MVC project, but a console application.
I feel like I am very close and maybe others will benefit from helping me solve this.
My specific questions...
1) Not sure where the 'code' parameter in the OAuth method originate??
2) How to perform the needed call backs with Instagram??
var config = new InstaSharp.InstagramConfig(location.InstagramClientId, location.InstagramClientSecret, "http://localhost");
string instagramLoginLink = InstagramLogin(config);
GetInstagram("soccer", config, instagramLoginLink);
public static async void GetInstagram(String tag, InstagramConfig config, string code)
{
OAuthResponse oAuthResponse = await OAuth(code, config);
var instagramPosts = await LoadInstagramPosts(tag, config, oAuthResponse);
if(instagramPosts.Data != null)
{
dynamic dyn = JsonConvert.DeserializeObject(instagramPosts.Data.ToString());
foreach (var data in dyn.data)
{
Console.WriteLine("{0} - {1}", data.filter, data.images.standard_resolution.url);
}
}
}
public static string InstagramLogin(InstagramConfig config)
{
var scopes = new List<OAuth.Scope>();
scopes.Add(InstaSharp.OAuth.Scope.Likes);
scopes.Add(InstaSharp.OAuth.Scope.Comments);
string link = InstaSharp.OAuth.AuthLink(config.OAuthUri + "authorize", config.ClientId, config.RedirectUri, scopes, InstaSharp.OAuth.ResponseType.Code);
return link;
}
public static async Task<OAuthResponse> OAuth(string code, InstagramConfig config)
{
// add this code to the auth object
var auth = new OAuth(config);
// now we have to call back to instagram and include the code they gave us
// along with our client secret
return await auth.RequestToken(code);
}
public static async Task<TagResponse> LoadInstagramPosts(String hashTagTerm, InstagramConfig config, OAuthResponse OAuth)
{
var tagApi = new InstaSharp.Endpoints.Tags(config, OAuth);
return await tagApi.Get("soccer");
}
I'm a bit late to the show, yet probably my answer will help someone who find this question when googling, someone like me.
The main problem with your approach is that Instagram is using OAuth authentication. I suggest you to google on OAuth to understand the principles, but I will try to explain the practical points of it below.
OAuth approach means that the result of the InstagramLogin method in the snippet above is not the code. It's the link where you need to send you user (yes, using a browser or a web-view) so that they can sign into their Instagram account and then authorize your application to access their data (so-called user consent screen).
In the end, after user consent, Instagram will redirect browser to the URL of your choice (it should be previously added in the list of allowed redirect urls in Instagram API -> Manage Clients (top-right corner) -> Create/Select client to Manage -> Security tab)
You can try set a breakpoint and copy the value of instagramLoginLink into your browser's address box. You will be able to see the whole flow of authentication and consent - and finally the redirect url that will most probably produce 404 in your browser.
This final link will contain the code in a get parameter. It's the so-called grant code that allows you to get an access token. This code is to be extracted from url and then used in your call to OAuth.RequestToken).
PS: Yes, everything I say above means that you need either a web app running that will redirect user to Instagram or a client-side app that will show the user a web view and somehow handle the moment when Instagram sends the user back to your redirect url - to grab the code and proceed.

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.

C# connect and login to webservice of betfair.com (newbie)

I am trying to connect to the following betfair.com web service.
https://api.betfair.com/global/v3/BFGlobalService.wsdl
Basically, I just want to log in and display this information in the console window.
I did this with PHP and it was so easy, but I am new to C# and am having trouble starting off.
Basically, I want to login and display the session token received from the web service on the screen.
I added the web service reference to the solution in visual studio .net 2010. In PHP we just had one request to make to the web service and it would return the data as an object. But it seems like in C#, I have to make 2 calls, Request and Response? Is this right?
Sorry, Im a newbie to c#, but I see great potential with the language, I really need some basic guidance as to how to proceed.
Currently, I have added the web service to my solution, What are the most basic things I have to do in order to login and receive a session token.
More Information about the Betfair Web Service can be found here:
http://bdp.betfair.com/index.php?option=com_weblinks&catid=59&Itemid=113
I tried looking through the example applications provided through betfair, but they are so complex, I just want the simplest way to Consume a webservice and login to retrieve a session token.
Thanks
EDIT
I was tryng something like this.
class Program
{
public static string username = "username";
public static string password = "password";
public static int softwareId = 82;
public static int productId = 0;
private static BFGlobalService m_globalService;
static void Main(string[] args)
{
m_globalService = new BFGlobalService();
}
static void Login()
{
LoginReq req = new LoginReq();
req.username = username;
req.password = password;
req.productId = productId;
req.vendorSoftwareId=softwareId;
LoginResp resp = m_globalService.login(req);
Console.WriteLine(resp.minorErrorCode);
Console.ReadKey();
}
}
But Im a noob so I dont even know if this is right!!
Any help to get me off my feet would be great!!, Plus a simple explanation if anything to complex.
Thanks!!
EDIT: Solution
I had to replace these 4 lines at the end.
string st = resp.errorCode.ToString();
string sessTok = resp.header.sessionToken;
Console.WriteLine(st + " " + sessTok);
Console.ReadKey();
You might want to download this app.
http://forum.bdp.betfair.com/attachment.php?s=18f39758fa8c2e850b27cf2d524903ed&attachmentid=20&d=1235565908
Its a reference implementation from Betfair in C#.
It is a really good foundation to start off with.
It has logins, async calls implementation and navigation of the different markets as well as how to place bets.
I extended it myself it really is very good
You're never calling your Login method. Try this:
static void Main(string[] args)
{
m_globalService = new BFGlobalService();
Login(); // calling your login method here...
}
Also: I'm not familiar with that API but I bet you're missing an initialization call between creating the BFGlobalService object and calling its Login method.
Here are a few pointers to get going with C#:
Make use of properties rather than public variables
Use try/catch exception handling on your web service calls
Try to not do too much work in your Main function. (I know you're just getting started but it's good to practice doing things the right way.) You should have a separate class that Main instantiates and invokes to initiate your web service interaction.

Need some help with code for getting a response from a Web service. Can you help me connect the dots?

Ok, its been a while since I've worked with a Web References. I need a refresher. I think I have about 80% of the code I need to get a response going but I'm missing something. Maybe you can help me :)
Given:
A web method called GetSomething in the list of methods when pointing to a .wsdl url.
This produces a few classes/objects:
GetSomethingRequest
GetSomethingCompletedEventHandler
GetSomethingCompletedEventArgs
myComplexType
Which I use to create this code:
void someMethodToTestResponse()
{
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
GetSomethingCompletedEventHandler handler = GetSomethingCompleted_Response;
//.... ok now what?
//handler.Invoke(???)
// at this point I'm supposed to send an object for source (request maybe?)
// and a new instance of GetSomethingCompletedEventArgs but that class is
// asking for stuff that makes me think that is not the right idea.
}
void GetSomethingCompleted_Response(object source, GetSomethingCompletedEventArgs args)
{
// get the result
var result = args.Result;
}
What am I doing wrong? What am I missing? Thanks in advance.
You don't need web service source codes. The web service can be implemented in Java. Creating service reference woks the same, as we really don't know what is on the other side.
So, try Add Service Reference in VS2008 and enter the url to working web service. VS will examine the wsdl on server and generate needed classes for you.
From than on, you just call the service as some ordinary method call. Meaning you don't have to fiddle with requests and http and such details. All that is hidden from you. Except in app.config where many WCF settings can be changed.
Ok, I figured out that I needed to find a Service type class. See this SO Post where it mentions:
private com.nowhere.somewebservice ws;
The issue was that the class they provide wasn't intellisensing for me and I figured it wasn't what I was looking for.
Here is how I would solve my problem:
blah.webservice.SomeMainServiceClass service = new SomeMainServiceClass();
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
object myResponse = service.GetSomething(request);

Categories

Resources