I am developing an Android app which uses a Web Service. I added a web service reference to my project (Right-Click on project -> Add Web Reference). When I use the web service without authentication everything works fine, but when I set credentials they are just not working. I'm getting this error:
The request failed with HTTP status 401: Unauthorized
Maybe someone can help me?
This is button click event function:
button.Click += delegate {
WebReference.WebPhysInvPocess client = new WebReference.WebPhysInvPocess(); //this is my web service
client.Credentials = new NetworkCredential("username", "password"); //adding crediantials
//client.Url = #"http://localhost:7053/DynamicsNAV-NAV6R2Prototype/WS/NVB%20Prototype/Codeunit/WebPhysInvPocess";
string blabla = "";
try
{
client.CratePhysInvBatch("S001", "RAUDONAS", ref blabla, "test");
TextView txt = FindViewById<TextView>(Resource.Id.textView1);
}
catch (Exception e)
{
TextView txt = FindViewById<TextView>(Resource.Id.textView1);
txt.Text = e.Message;
}
};
When I compile the code as a windows .net application everything works.
Have you checked your delegation?
Related
I try connect my xamarin forms app with asmx web service.
I create DependencyServices and add service call here.
public string GetConferences()
{
using (service = new worksops())//my service
{
service.Credentials = new NetworkCredentials("username","password");
var conferencesjson = service.GetConferenceList();
return conferencesjson;
}
}
this code working perfect on wpf project with c# , but here in xamarin i get WebException "HTTP status 401: Unauthorized".
more infos :
inside in Responce i found System.NotImplementedException on the IsMutuallyAuthenticated.
Any ideas ??
Thanks
Have you tried like this:
service.ClientCredentials.UserName.UserName = "username";
service.ClientCredentials.UserName.Password = "password";
Not Able to login using .Net Web Application(C#) in Net Suite...
If Any One Have Solution please give me step by step
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
NetSuiteService service = new NetSuiteService();
service.CookieContainer = new CookieContainer();
//invoke the login operation
Passport passport = new Passport();
passport.account = "TSTDRV986543";
passport.email = txtUserName.Text;
passport.password = txtPassword.Text;
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
Status status = service.login(passport).status;
}
}
I am using https://webservices.netsuite.com/wsdl/v2014_2_0/netsuite.wsdl This url to import web services and also I already change all URL type.
You should check out the SuiteTalk sample applications for sample requests to NetSuite, both in C# and in Java: http://www.netsuite.com/portal/developers/resources/suitetalk-sample-applications.shtml
It is also possible to troubleshoot the SOAP requests and responses by going in NetSuite, under Setup -> Integration -> Web Service Usage Logs.
I am confused about publishing a post on facebook using C# sdk
I want to publish Name ,Description and photo on my page:
Do i need "publish_actions " in "items in review"(permissions)? because it is my own page .
When i try to add publish_actions ,facebook asks for privacy policy url ,How am i supposed to make it using C# Desktop Application, I didn't Found useful help on google.
Settings:
I have added http: //localhost:80/ to my site URL and:
http://abbasnaqvi512.tumblr.com/ to Valid OAuth redirect URIs.
Native or desktop app?=Yes
Is your App Secret embedded?=No
Client OAuth Login=yes
Embedded browser OAuth Login=NO
App Secret Proof for Server API calls=No
Require 2-factor reauthorization=No
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
if (e.Url.OriginalString.Contains("assets") && e.Url.OriginalString.Contains("code"))
{
code = Regex.Matches(e.Url.OriginalString, "assets.tumblr.com.*?code%3D(?<data>.*?)&")[0].Groups["data"].Value;
richTextBox1.Text += "\n\n" + code + "\n\n";
if (String.IsNullOrEmpty(code) == false)
{
webBrowser1.Stop();
webBrowser1.Dispose();
ShareOnFB();
}
}
}
catch (Exception)
{
}
}
private void ShareOnFB()
{
string pageId = "ABC";
FacebookClient client = new FacebookClient(code);
dynamic messagePost = new ExpandoObject();
messagePost.access_token = code;
messagePost.picture = "http://fc02.ostadreza-d6pkzrd.jpg";
// messagePost.link = "http://www.examplearticle.com";
messagePost.name = "NAME";
messagePost.description = "DESCRIPTION";
var result = client.Post(string.Format("/{0}/feed", pageId), messagePost);
richTextBox1.Text += "\n\n"+result+"\n\n";
}
Rightnow it is giving me Error
"Malformed access token AQA44CIJCyoV7_Xlz3mtvdPErPBrmtF6ykz6teCc9QINrfePHxEOiQKIyl8wgxH1mvQxEtLE-xnVfdyfiE38eA2M1YU7RS22MNIKNUh5wMmd2zwPCLj30PiEaq6CKIfcq9yIvq_slblOWmE4LYcynyH_pJuZcPc3EqLCQoCUBtSO58X1WtiohRoRvq70QWHpZec-7jhzUQnW75nlk4wpEwcJ9yOcBlPbne72sV6yX_hqndI5RKVDjqRJzdOscOblbLCkC1xtI0rMD1bCJufvpAa-tMsIyG6ATqrk6TNqXXASlcvialbzh0WttS2x-j_J59LF7cBh22T18P8qOly5cOwF"
Thanks for reading my question ,Kindly help me,
Update: I have added publish_actions in review by adding tumblr privacy policy url ,Notes and screen shots of my application ,It is on review
I am developing a Provider-hosted application for SharePoint 2013.
I debug this application on a Development Collection with both Windows Authentication and FBA (Form Based Authentication) activated. I can successfully access to this collection with my Windows account or a user stored in SQL Server. Both accounts are administrators of the collection with full control on it.
When I run the application, I get the usual window asking for the authentication mode I want. After being successfully connected with a user (both are working), I get : "The remote server returned an error: (403) Forbidden" on clientContext.ExecuteQuery().
var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
var hostWeb = Page.Request["SPHostUrl"];
using (var clientContext = new ClientContext(hostWeb))
{
clientContext.Load(clientContext.Web, web => web.Title);
clientContext.ExecuteQuery();
Response.Write(clientContext.Web.Title);
}
I should precise that, if I disable the FBA on the collection and only let the Windows authentication, it works like a charm.
What am I doing wrong ? Any idea ?
thanks for helping
public void Whatevermethod()
{
using (SP.ClientContext clientContext = new SP.ClientContext("http://server/collection"))
{
//Configure the handler to set FBA mode
clientContext.ExecutingWebRequest += new EventHandler<SP.WebRequestEventArgs>(ctx_MixedAuthRequest);
//Use the default mode to execute under the credentials of this process
clientContext.AuthenticationMode = SP.ClientAuthenticationMode.Default;
clientContext.Credentials = System.Net.CredentialCache.DefaultCredentials;
clientContext.ExecuteQuery();
}
}
private void ctx_MixedAuthRequest(object sender, SP.WebRequestEventArgs e)
{
try
{
//Add the header that tells SharePoint to use FBA
e.WebRequestExecutor.RequestHeaders.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
}
catch (Exception ex)
{
string error = ex.Message;
}
}
var hostWeb = Page.Request["SPHostUrl"];
using (var clientContext = new ClientContext(hostWeb))
{
clientContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(clientContext_ExecutingWebRequest);
clientContext.Load(clientContext.Web, web => web.Title);
clientContext.ExecuteQuery();
Response.Write(clientContext.Web.Title);
}
static void clientContext_ExecutingWebRequest(object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
}
I have a console application to download a file from a SharePoint site. The sharepoint site uses claims based authentication.
This code throws a 403 Forbidden exception. The specified Network credential has full access to the site, and is able to download the same file from a browser.
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential(username,Password,domain);
byte[] fileData = webClient.DownloadData(urlOfAFile);
FileStream file = File.Create(localPath);
file.Write(fileData, 0, fileData.Length);
Any idea how to fix this?
Maybe a bit late, but adding the right request header before making the request solves the problem:
webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
I also encounter this issue, and below is my research:
{
ClientContext m_clientContext = new ClientContext(strSiteUrl);
m_clientContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(ctx_MixedAuthRequest);
m_clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
m_clientContext.Credentials = new NetworkCredential(uname, pwd);
Web m_currentWeb = m_clientContext.Web;
m_clientContext.Load(m_currentWeb);
m_clientContext.ExecuteQuery();
}
private void ctx_MixedAuthRequest(object sender, WebRequestEventArgs e)
{
try
{
//Add the header that tells SharePoint to use Windows authentication.
e.WebRequestExecutor.RequestHeaders.Add(
"X-FORMS_BASED_AUTH_ACCEPTED", "f");
}
catch (Exception ex)
{
MessageBox.Show("Error setting authentication header: " + ex.Message);
}
}
here is the article: https://msdn.microsoft.com/en-us/library/office/hh124553(v=office.14).aspx