I am using MsgReader library for parsing outlook messages. But for signed emails ( SignatureIsValid and SignedCertificate) properties are not initializing.
Here is my sample code
MsgReader.Outlook.Storage.Message mailMessage;
using (Stream stream = new FileStream(tmpFileName, FileMode.Open))
{
mailMessage = new MsgReader.Outlook.Storage.Message(stream,FileAccess.Read);
}
Anyone knows how to do this?
Regards,
Jhan Zaib
Related
I am not able to send email with SendGrid using the V3 API in a console application. It works fine in my Web Application. I created a test console project and used the sample code from the SendGrid site. When the command to send the message is called, the application simply exits. I cannot read any response from the call.
This is in VB.Net. Sorry, I think I am the only person on Earth who codes in VB.
If I execute this code in the sample sendgrid-csharp-main from GitHub, it works fine. I cannot find anything in the sample code that looks any different from my code in the section that actually calls the send message part (other than having to convert to VB).
Does anyone see ANYTHING wrong in this code? I am using the .Net 4.7.2 framework.
This is the entirety of the test code. I have been spinning my wheels searching for help for too long and I am desperate now.
Imports System.Net.Http
Imports SendGrid
Imports SendGrid.Helpers.Mail
Module Module1
Sub Main()
TryIt().ConfigureAwait(True)
End Sub
Private Async Function TryIt() As Task
Dim HttpClient As HttpClient = New HttpClient()
Dim apiKey = "my private api key"
Dim client = New SendGridClient(HttpClient, New SendGridClientOptions With {
.ApiKey = apiKey,
.HttpErrorAsException = True
})
Dim from = New EmailAddress("msie#msinvoiceExchange.com", "MSIE")
Dim subject = "Hello World from the Twilio SendGrid CSharp Library Helper!"
Dim toEmail = New EmailAddress("joe#invoicesanywhere.com", "Joe")
Dim plainTextContent = "Hello, Email from the helper [SendSingleEmailAsync]!"
Dim htmlContent = "<strong>Hello, Email from the helper! [SendSingleEmailAsync]</strong>"
Dim msg As New SendGridMessage With {
.From = from,
.Subject = subject,
.PlainTextContent = plainTextContent,
.HtmlContent = htmlContent
}
msg.AddTo(toEmail)
Dim myResponse As Response
myResponse = Await client.SendEmailAsync(msg)
Console.WriteLine(msg.Serialize())
Console.WriteLine(myResponse.StatusCode)
Console.WriteLine(myResponse.Headers)
Console.WriteLine(vbLf & vbLf & "Press <Enter> to continue.")
Console.ReadLine()
End Function
End Module
It figures. As soon as I get desperate enough to post a question, I figure out something that works.
I just hope that someone else has the same problem and finds this answer helpful.
This is the change I had to make to get this to work
Sub Main()
TryIt().Wait()
End Sub
I call my service in wcf as you can see :
ClientRequest.Headers["Content-type"] = "application/json";
string result = ClientRequest.DownloadString(ServiceHostName + "/NajaService.svc/GetCarData/" + plaque);
var javascriptserializer = new JavaScriptSerializer();
return javascriptserializer.Deserialize<NajaResult>(result);
But the returned data is like this :
{"CarColor":"آبي سير","CarModel":"1383","CarTip":"ال ايکس","CarType":"سواري","Chassis":"83844131","Family":"####","FuelType":1,"MotorNum":"12483068683","Name":"####","NationalCode":"0000000000","Plaque":"11-426د61","PlaqueCoded":110561426,"PlaqueType":"","SystemType":"سمند","VinNo":"IRFC831V3GJ844131"}
I converted it to UTF8 byte and again convert it to utf8 string but not solved.
The encoded data is in Persian language .
I traced the request in fiddler and i found that the data is come with the correct format as you can see ,But in my code is changed
The WebRequest contains the Encoding property you can set up before downloading the service reply. Details are here: https://msdn.microsoft.com/en-us/library/system.net.webclient.encoding(v=vs.110).aspx
I would like to retrieve data from a restful web service in order to save this data into an object. The data retrieval works in principal and the JSON string can be shown in a text box. However, I struggle making the data usable in C# - after some research and own programming, I still get errors when deserialising that I am not able to fix:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft;
using System.IO;
using System.Net;
namespace Datenbankabfrage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGet_Click(object sender, EventArgs e)
{
// Create a request for the URL.
WebRequest request = WebRequest.Create(
"URL");
// Get the response.
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
Artikel ErsterA = new Artikel();
Newtonsoft.Json.JsonConvert.PopulateObject(responseFromServer, ErsterA);
//txtAusgabeAA.Text = responseFromServer;
reader.Close();
response.Close();
}
}
}
Here a picture of the error massage, which states:
An unhandled exception of type
'Newtonsoft.Json.JsonSerializationException` occurred in
Newtonsoft.Json.dll
Additional information: Cannot populate JSON array onto type
'Datenbankabfrage.Artikel'. Path ", line 1, position 1.
Any help is appreciated!
Your problem is explained by the exception message:
Cannot populate JSON array onto type 'Datenbankabfrage.Artikel'. Path
", line 1, position 1.
For background, JSON has two types of container:
An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).
Json.NET maps .NET IEnumerable, Lists, and Arrays (other than dictionaries) to JSON arrays.
An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace).
Json.NET maps non-enumerable .NET objects such as your Artikel to JSON objects.
Thus from the exception it must be that the root container in your JSON string (not included in your question) is an array, and so cannot be populated onto a pre-existing non-enumerable POCO with JsonConvert.PopulateObject().
Instead, the JSON needs to be deserialized as follows:
var list = JsonConvert.DeserializeObject<List<Artikel>>(responseFromServer);
I want to use a ClientRequestFilter to modify outgoing REST requests of my application without changing the source code.
So far, I have only found ways to register my filter programmatically:
Client client = ClientBuilder.newClient();
client.register(new MyClientRequestFilterImpl());
webtarget = client.target(uriBuilder);
Is it possible to use the web.xml or similar?
As far as I know there is no such way but you can easily read a configuration file on your own. Assuming following file:
com.foo.bar.Filter1
com.foo.bar.Filter2
You can register the filters like this:
List<String> filters = Files.readAllLines(Paths.get(new URI("/your/config/file")), Charset.forName("UTF-8"));
Client client = ClientBuilder.newClient();
for (String filter : filters) {
client.register(Class.forName(filter));
}
I'm working on an app that requires extracting data from an xml web service, then I want to store that data (images+titles+datetime ...) to display it on my app then select an item and navigate to another page that displays more info about this item.
Is there a detailed tutorial that explains the parsing and storing process clearly (with the threads) because I'm gonna need it a lot for my app.Thanks!
I usually use this method, but didn't always get me what i want:
var doc = XDocument.Load(new StringReader(e.Result));
var items = from c in doc.Descendants("item")
select new RSSitem()
{
Title = c.Element("title").Value,
Photo = c.Element("img").Attribute("src").Value,
Description = c.Element("description").Value,
Link = c.Element("link").Value,
};
ListBoxNews.ItemsSource = items;
Sounds like you are in over your head (based on the vague nature of your question). So I'm offering my advise to get up to speed, so you can get started and ask a question that we can help give a definitive answer to.
With WP7 and .NET you shouldn't really have to do much manual parsing of Web Services. You should be able to add a Service Reference and generate a proxy which will handle this for you. This will also generate business objects for the data returned by your service.
Once you have that done, you can look into Windows Phone Navigation which should help you transition between pages in your application.
To consume web services:
String baseUri = “your service URI";
WebClient wc = new WebClient();
public MainPage()
{
InitializeComponent();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_downloadstringcompleted);
// event handler that will handle the ‘downloadstringsompleted’ event
wc.DownloadStringAsync(new Uri(baseUri));
// this method will download your string URI asynchronously
}
void wc_downloadstringcompleted(Object sender, DownloadStringCompletedEventArgs e)
{
// method will get fired after URI download completes
// writes your every code here
}
To parse the data:
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
break;
case XmlNodeType.Text:
break;
case XmlNodeType.EndElement:
break;
}
}
}
}
To store in isolated storage: http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragesettings%28v=vs.95%29.aspx
For navigation:
NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + navigationstring, UriKind.Relative));