Here I am put my code which is "An exception occurred during a WebClient request" i put breakpoint and check .it will so this error .for developing i am using visual studio 2012 ultimate with windows phone sdk8.0 and if request is done successful than my response is in json string .that will show in messagebox .now it show me "System.Net.Webexception:An exception occurred during a WebClient request."
public match()
{
InitializeComponent();
Loaded += new RoutedEventHandler(profile1_loaded);
}
void profile1_loaded(object sender, RoutedEventArgs e)
{
WebClient wc2 = new WebClient();
var URI = new Uri("http://192.168.1.17/eyematch/rest1-7-2/api/match");
wc2.Headers["Content-Type"] = "application/x-www-form-urlencoded";
wc2.UploadStringCompleted +=
new UploadStringCompletedEventHandler(wc2_UploadStringCompleted);
wc2.UploadStringAsync(
URI, "GET", "action=getMatchNotificationData&sKey=" +
GlobalVariables.skey + "&uKey=" + GlobalVariables.ukey);
}
private void wc2_UploadStringCompleted(object sender, UploadStringCompletedEventArgs er)
{
try
{
MessageBox.Show(er.Result);
}
catch (Exception eu)
{
MessageBox.Show(eu.ToString());
}
}
thank you in advance....
Are you testing this in the emulator or on a physical device? Chances are the address is inaccessible given your network configuration (especially since it is a local network IP).
A helpful hint to other people running into this error message: the exception has a .InnerException, so if you change the code above to also output "eu.InnerException", you can get more info.
Related
We are converting our old webservices (asmx) to use https, trying to get it working locally.
I have a test app I wrote in winforms jsut to call the service.
Trying to modify it to call via https, following this pattern
https://www.codeproject.com/Questions/751059/Call-https-Webservice-in-Console-Application
(Not sure I trust this pattern 100%, but it's a place to start, looks like it's trying to ignore all errors)
private void button8_Click(object sender, EventArgs e)
{
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
}
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy()
{
AdStudent.ADStudent ws = new AdStudent.ADStudent();
ws.Url = "https://localhost/JCDCADStudent/ADStudent.asmx";
try
{
string str = ws.GetGuidString("Brown.Eric");
MessageBox.Show("secure guid is " + str + ".");
}
catch (Exception ex)
{
string cleanMsg = GetCleanMsg(ex.Message);
MessageBox.Show("\n\n " + cleanMsg + "\n\n\n\n\nProgrammer Msg:\n\n" + ex.Message, "Error");
}
}
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest req, int problem)
{
return true;
}
private string GetCleanMsg(string message)
{
string startTag = "<ClientMsg>";
string endTag = "</ClientMsg>";
Int32 start = message.IndexOf(startTag) + startTag.Length;
Int32 end = message.IndexOf(endTag);
try
{
return message.Substring(start, end - start);
}
catch (Exception ex)
{
return "UNABLE TO PARSE MESSAGE : \n " + message;
}
}
}
}
I get the exception
{"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."}
inner exception
The remote certificate is invalid according to the validation procedure.
When I try and just run the HTTPS in the browser, it complains that like the title or subject field is not formatted correctly. but If I tell it to ignore that it opens the web service, I'm guessing that is the problem,
How do I fix it?
How do I get a better error like the one the browser gives me, to report in my app?
The cert was provided by our IT team, I'm not sure I can get it changed, it's a long-standing cert used for Dev.
Maybe I can get it regenerated correctly (it's applied to our machines via network policy)
I'm totally new in xamarin.
I use Visual Studio 2017 Community and I write a very simple code: I want to connect to a basic WCF service.
The link to the service:
http://services.adserviceitalia.it/Service1.svc
(method GetHello, input string and return string... very basic method)
I read a lot of samples... I add a reference to the services, generate the proxy class... ok!!
public partial class MainPage : ContentPage
{
private wcfs.Service1Client ws;
public MainPage()
{
InitializeComponent();
var endpoint = new EndpointAddress("http://services.adserviceitalia.it/Service1.svc");
var binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
ws = new wcfs.Service1Client(binding,endpoint);
ws.GetHelloCompleted += Handle_HelloWorldCompleted;
}
private void Button_Clicked(object sender, EventArgs e)
{
ws.GetHelloAsync("Mark");
}
private void Handle_HelloWorldCompleted(object sender, wcfs.GetHelloCompletedEventArgs args)
{
label1.Text = args.Result;
}
}
}
It works in UWP debug...
Connection with WCF... Hello World working in UWP
I got an unhandled exception in Android...
In Android Manifest all permission are cheched. The Android emulator is connected to internet...
Every help would be extremely appreciated!! Thanks in advance... and excuse me form my english.
Ops...
First: thanks to all!!
In my log i read this:
04-27 14:11:30.106 E/mono-rt ( 5308): [ERROR] FATAL UNHANDLED EXCEPTION: Android.Util.AndroidRuntimeException: Only the original thread that created a view hierarchy can touch its views.
Seems that problem is that I try to update the interface directly in Handle_HelloWorldCompleted with WCF respose:
label1.Text = args.Result;
... in I modify the code in this way:
//label1.Text = args.Result;
System.Diagnostics.Debug.WriteLine(args.Result);
I can see that arg.Result is populated by the WCF response "Hola Mark" (ergo: the connection with the service works!!) .
Notice i've this behavior in Android debug only.
How I can update that label1 ??
An exception of type System.Reflection.TargetInvocationException
occurred in System.ni.dll but was not handled in user code.
var client = new WebClient();
client.DownloadStringCompleted += (sender, e) =>
{
XDocument doc = XDocument.Load(e.Result);
};
client.DownloadStringAsync(new Uri("http://mylocation.com/myfile.php?userid=xyz"));
Maybe you could add a bit of error checking to narrow things down a bit
WebClient client = new WebClient();
client.DownloadStringCompleted += (sender, e) =>
{
if (e.Error != null && !string.IsNullOrEmpty(e.Result))
{
XDocument doc = XDocument.Load(e.Result);
}
};
client.DownloadStringAsync(new Uri("http://mylocation.com/myfile.php?userid=xyz"));
Maybe the data passed between app and Service exceed certain size. For example, when you pass a string larger than 8K chars back to Service, you will get a 404 error. need to change the default configuration to handle large data.
Mostly e.Result or one of its children is null and hence this exception is being thrown.
Go to Tools -> Options -> Debugging and select Enable Just My Code in Visual Studio. That should help you figure out what the problem is.
I have the following code where I'm trying to download 3 different files from the users SkyDrive Account.
I'm using the SkyDrive API for Windows Phone development.
client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedVI);
client.DownloadAsync(fileIdVehicleItems);
client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedHI);
client.DownloadAsync(fileIdHistoryItems);
client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompletedRI);
client.DownloadAsync(fileIdRepairItems);
When I run this, the only method that gets called is the OnDownloadCompletedVI. All the files that are being downloaded are running through this method which is causing an error.
What am I doing incorrectly?
Update
I have the following method, but I have 2 other similar methods that do the exact same thing except it loads different objects (based off of the downloaded files).
The error I'm currently receiving:
An exception of type 'System.ArgumentException' occurred in
mscorlib.ni.dll but was not handled in user code
void OnDownloadCompletedVI(object sender, LiveDownloadCompletedEventArgs e)
{
if (e.Result != null)
{
using (var stream_vi = e.Result)
{
StreamReader SRVI = new StreamReader(stream_vi);
string contentVI = "";
contentVI = SRVI.ReadToEnd();
StringReader rdr_vi = new StringReader(contentVI);
XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<vehicle>));
ObservableCollection<vehicle> importedVehicles = new ObservableCollection<vehicle>();
importedVehicles = (ObservableCollection<vehicle>)serializer.Deserialize(rdr_vi);
StorageHelper.Save<ObservableCollection<vehicle>>(App.vehicleData, importedVehicles);
}
//e.Result.Close();
}
else
{
infoTextBlock.Text = "Error downloading file: " + e.Error.ToString();
}
}
Actually all three methods should be called. Of course, if the first method is called and throws an exception the other two won't trigger.
What you can do is either create a new client for each call, or download them in order, so when the OnDownloadCompletedVI method is complete, remove the event handler for OnDownloadCompletedVI and add the one for OnDownloadCompletedHI and then trigger the client.DownloadAsync(fileIdHistoryItems); at the end of the method.
I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I have deployed a publishing portal. I am developing a ASP.Net web application using VSTS 2008 + C# + .Net 3.5 + ASP.Net + SharePoint Server 2007 SDK.
Here is my code snippets and I got error -- "Updates are currently disallowed on GET requests". Any ideas how to fix?
Microsoft.SharePoint.SPException: Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.
protected void Page_Load(object sender, EventArgs e)
{
try
{
SPWebApplication webApp = SPContext.Current.Site.WebApplication;
SPSiteCollection siteCollections = webApp.Sites;
foreach (SPSite item in siteCollections)
{
SPWeb webItem = item.OpenWeb();
webItem.AllowUnsafeUpdates = true;
}
SPSite newSiteCollection = siteCollections.Add("sites/myblog",
"New Sample Site", "New Sample Site Description", 1033, "BLOG#0",
"foo\\foouser", "Owner name", "owneremail#foo.com");
}
catch (Exception ex)
{
Response.Write(ex.ToString() + "\t" + ex.StackTrace);
}
}
The problem why you are not allowed to read/write to database on GET request is because your code will be exploitable via a cross-site scripting. Read about AllowUnsafeUpdates consequences here.
Anyway, if you like, you can set this SPWeb.AllowUnsafeUpdates to true, but use it like this:
try {
web.AllowUnsafeUpdates = true;
...
}
finally {
web.AllowUnsafeUpdates = false;
}
Add a check to ensure that you are getting a POST instead of a GET before you attempt to allow updates. Make sure that whatever is making the change does it via a POST request rather than using URL parameters and a GET.
if (IsPostBack)
{
...
}