Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am using ASP.Net web api for my service, that is called from a third party application. When I test it in chrome postman it works fine in localhost and deployed server, but I have tried it in fiddler, hurl it and the string val is always null, should I be adding something else? I cant understand why it works fine in postman! Going kinda crazy with this one !
Thanks in advance
public bool PostProperty([FromBody] string val)
{
try
{
var reader = new StringReader(val);
var serializer = new XmlSerializer(typeof(property));
var instance = (property)serializer.Deserialize(reader);
}
}
Change your signature to be
public async Task<bool> PostProperty()
{
try
{
var reader = new StringReader(await Request.Content.ReadAsStringAsync());
var serializer = new XmlSerializer(typeof(property));
var instance = (property)serializer.Deserialize(reader);
}
}
or
public bool PostProperty([FromBody] property val)
{
}
If you do the second option, you might have to add the following line to your setup,
config.Formatters.XmlFormatter.UseXmlSerializer = true;
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I'm trying to figure out how to build a Console Application in C# that essentially mimics google maps. I need to be able to enter an address (even if I abbreviate a word. EX: Silverbell Dr) and output the correct spelling (Silverbell Drive).
The goal here is to be able to enter an address in the search, even if the address spelling is incorrect, and output a value that is close enough to the user input that it won't send back a null value.
If anyone has anything that is similar to this, I would greatly appreciate the help!
Boss gave me this assignment knowing that I hardly have a base knowledge on the subject
One way to do it would be to use Googles geocode API. You can pass it a partial address and it will do it's best to return the normalized address for you. If the address isn't very specific, you will get back more than one.
Here's a code example for calling the API and parsing the results:
private static List<string> GetNormalizedAddresses(string address)
{
// Generate request Uri
var baseUrl = "http://maps.googleapis.com/maps/api/geocode/xml";
var requestUri = $"{baseUrl}?address={Uri.EscapeDataString(address)}&sensor=false";
// Get response
var request = WebRequest.Create(requestUri);
var response = request.GetResponse();
var xDoc = XDocument.Load(response.GetResponseStream());
var results = xDoc.Element("GeocodeResponse")?.Elements("result").ToList();
var normalizedAddresses = new List<string>();
// Populate results
if (results != null)
{
normalizedAddresses.AddRange(results
.Select(result => result.Element("formatted_address")?.Value)
.Where(formattedAddress => !string.IsNullOrWhiteSpace(formattedAddress)));
}
return normalizedAddresses;
}
Then, you could call it like so:
while(true)
{
Console.Write("Enter a partial address: ");
var partialAddress = Console.ReadLine();
Console.WriteLine(new string ('-', 25 + partialAddress.Length));
var normalizedAddress = GetNormalizedAddresses(partialAddress);
if (!normalizedAddress.Any())
{
Console.WriteLine("Sorry, couldn't find anything.");
}
else
{
Console.WriteLine("That address normalizes to:");
Console.WriteLine($" - {string.Join($"\n - ", normalizedAddress)}");
}
Console.WriteLine("\n");
}
Output
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Here this is my code I try to send text to the text box but I can't it is not working.
ITestControl PointBuildWin = new UITestControl();
PointBuildWin.TechnologyName = "MSAA";
PointBuildWin.SearchProperties[UITestControl.PropertyNames.ClassName] = "WindowsForms10.Window.8.app.0.378734a";
PointBuildWin.SearchProperties[UITestControl.PropertyNames.FriendlyName] = "XLS80ePSPointUtility";
Thread.Sleep(3000);
WinRadioButton UpgradePointBuildBtn = new WinRadioButton(PointBuildWin);
UpgradePointBuildBtn.SearchProperties[WinRadioButton.PropertyNames.Name] = "Upgrade from earlier version of EBI and XLS80ePS";
Mouse.Click(UpgradePointBuildBtn);
Thread.Sleep(1000);
WinCheckBox PointSpecButton = new WinCheckBox(PointBuildWin);
PointSpecButton.SearchProperties[WinCheckBox.PropertyNames.Name] = "Point name specific";
Mouse.Click(PointSpecButton);
Thread.Sleep(2000);
WinEdit TextInput = new WinEdit(PointBuildWin);
TextInput.SearchProperties[WinEdit.PropertyNames.ClassName] = "WindowsForms10.EDIT.app.0.378734a";
Thread.Sleep(2000);
Mouse.Click(TextInput);
TextInput.SetFocus();
Keyboard.SendKeys(TextInput, "Test");
try
TextInput.DrawHighlight() before Mouse.Click(TextInput) and confirm the search properties are pointing to right control.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to get blocked file extension and maximum file size for attachment set by admin in c# code .Below image displays what I actually want using c# code.
Please suggest me answer.
Please use the following code to get any property in the System Settings.
var query = new QueryExpression("organization")
{
ColumnSet = new ColumnSet("blockedattachments", "maxuploadfilesize")
};
EntityCollection orgCollection = _service.RetrieveMultiple(query);
if (orgCollection.Entities.Count > 0)
{
Entity org = orgCollection.Entities.First();
string blockedattachments = org.GetAttributeValue<string>("blockedattachments");
int numberMaxUploadFileSize = org.GetAttributeValue<int>("maxuploadfilesize");
}
Try using below code, it is tested and working fine.
var query = new QueryExpression("organization")
{
ColumnSet = new ColumnSet("blockedattachments", "maxuploadfilesize")
};
var record = service.RetrieveMultiple(query).Entities.FirstOrDefault();
if (record != null)
{
var blockedAttachments = record.GetAttributeValue<string>("blockedattachments");
var maxAttachmentSize = record.GetAttributeValue<int>("maxuploadfilesize");
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So I have this method in my project:
public static String MD5Hash(string TextToHash)
{
if ((TextToHash == null) || (TextToHash.Length == 0))
{
return String.Empty;
}
MD5 md5 = new MD5CryptoServiceProvider();
byte[] textToHash = Encoding.Default.GetBytes(TextToHash);
byte[] result = md5.ComputeHash(textToHash);
return System.BitConverter.ToString(result);
}
And I've tried testing like this:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BugMon;
namespace BugMonTesting
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
string pwd = "Password";
string expected = "DC-64-7E-B6-5E-67-11-E1-55-37-52-18-21-2B-39-64";
frmLogIn.MD5Hash(pwd);
Assert.AreEqual(pwd, expected);
}
}
}
But the string pwd does not seem to be passing through the Method when I run the test and stays as "Password".
What am I doing wrong?
Sorry if this is obvious but I've never had to use these tests before.
You're never doing anything with the return value from MD5Hash.
Try this:
string hash = frmLogIn.MD5Hash(pwd);
Assert.AreEqual(hash, expected);
Note that this will only work if MD5Hash returns a string formatted like the expected variable.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a Windows application that gets data from a webservice.
I need to use JSON to post or get data from the webservice.
What is the best way to do that? In the webservice and in the Windows application?
Please specify in details with a code sample because I am new to JSON.
Use Json.NET
You can download and install it from NuGet.
To use it you create a C# model that matches your Json and then call:
string json = "";
MyObject obj = JsonConvert.DeserializeObject<MyObject>(json);
and to Serialise:
string json = JsonConvert.SerializeObject(new MyObject {});
See the documentation for further examples and explanation.
As an alternative to Json.Net, you can use WCF as described in this article. WCF is a service framework provided by Microsoft as part of .Net.
It is difficult to give examples with out snippets of your classes and what you are trying to achieve.
However take a look at this function you could have in your webservice
using Newsoft.Json;
public JsonResult FunctionName(string JsonString)
{
if (JsonString!= null)
{
YourObject YourObjectInstance = new YourObject ();
try
{
YourObjectInstance = JsonConvert.DeserializeObject<YourObject >(JsonString);
//do something with the data
// return a Json response of either your object or another object type
return Json(YourObjectInstance, JsonRequestBehavior.AllowGet);
}
catch
{
return new JsonResult(); //return empty JsonResult
}
}
else
{
return new JsonResult(); //return empty JsonResult
}
}
}