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";
Related
I have a WCF service which has a method named ArchiveFile(string fileName) which basically archives files. I have created a proxy project using svcutil and added its reference created in my client application and is consuming the service as follows:
var binding = new WSHttpBinding { Security = new WSHttpSecurity() { Mode = SecurityMode.None } };
var address = new EndpointAddress(this.TargetUrl);
var fileService = new FileServiceClient(binding, address);'
I want to know how do I determine the Http Status Code (200 - OK or any other) for the WCF Service call.
We can get the http status code through WebOperationContext Class:
WebOperationContext statuscode = WebOperationContext.Current;
Console.WriteLine(statuscode.OutgoingResponse.StatusCode);
For more information about WebOperationContext,please refer to the following link:
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.web.weboperationcontext?view=netframework-4.8
We are developing an iOS shopping cart application in c# and Visual Studio 2017 for Xamarin. We are using rest web services, Here I could not call web services. when I call web service I am getting null response with an error[ConnectFailure (Connection refused)]. My question is How to get a value from localhost URL like [http://localhost:56207/api/Users/Raju/Password#123]. When I enter this URL in the browser I am getting true or false depending upon user and password validation.I request you to help me to resolve this issue.I paste the code in below:
public class RestInterfaceImp : IRestLogin
{
HttpClient client;
private const string WebServiceUrl = "http://localhost:56207/api/Users/Raju/Password#123";
public async Task<List<User>> RefreshDataAsync()
{
try
{
var httpClient = new HttpClient();
var resp = await httpClient.GetAsync(WebServiceUrl);
if (resp.IsSuccessStatusCode)
{
var respStr = await resp.Content.ReadAsStringAsync();
var listaAtletas = JsonConvert.DeserializeObject<List<User>>(respStr);
}
}
catch (HttpRequestException e)
{
Debug.WriteLine(e.InnerException.Message);
}
return null;
}
}
Whenever we need to expose a local api to a simulator like you are doing, we use ngrok:
https://github.com/inconshreveable/ngrok
For some reason their website is down right now so it's possible they are no longer a thing but here is the url:
https://ngrok.com/
Suddenly i got reports form user that a list in my app didn't show any data - It worked fine on my device. Later i found out that everything works fine and dandy on all android devices with 6.0 installed - every android version below 6.0(Marshmallow), wont get data transferred! I am at a loss - have no idea what has happened or how to fix this.... Help!
Does anyone recognize this or have possible solution to how this can be fixed?
In my forms app i have a portable library where i have a class handling the SOAP webservice, it is implemented like below:
public class soapwebservice
{
//private Uri baseUri = new Uri("uri");
private static DataConnection _instance = null;
private HttpClient client = null;
//Contructor
private DataConnection()
{
client = new HttpClient(new NativeMessageHandler());
client.BaseAddress = baseUri;
}
public static DataConnection Instance { get { if (_instance == null) _instance = new DataConnection(); return _instance; } }
public async Task<Other.ServiceResponse> RefreshRouteList()
{
try
{
var soapString = this.constructRefreshsoap();
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("SOAPAction", "https://trolderuterne.play2know.dk/GetRoutes");
var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
using (var response = await client.PostAsync("/Classes/mobileServices.asmx", content))
{
if (response.IsSuccessStatusCode)
{
var soapResponse = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<Other.ServiceResponse>(ParseSoapResponse(soapResponse));
}
return new ServiceResponse { Code = Codes.ServerError, Message = response.StatusCode.ToString() };
}
}
catch (Exception ex)
{
return new ServiceResponse
{
Code = Codes.ServerError,
Message = ex.Message
};
}
finally
{
}
}
The error message i get when running the app is:
"Error: NameResolutionFailure"
I have now tried to consume the webservice directly in the android project instead of the PCL.
Just to mention it i have my webservice going over a proxy, due to security. It still works on 6.0, but when i go to a simulator running 4.4 i still get error: "Error: NameResolutionFailure".
I tried grabbing the original webservice directly from our server and I get the following error message: "Error: ConnectFailure (Network is unreachable)"
Hopefully someone has some insight, and can tell me how to get the data i need from the webservice in devices below Android 6.0!
NameResolutionFailure looks like a DNS error. But you're going through a proxy, so who knows what they are doing. Did they change something recently? Can you try to resolve the name into an IP both with and without the proxy, over WiFi and mobile data too?
ConnectFailure looks like you cannot connect to the server. Can you try to get data directly from the IP address instead? Try both directly and through the proxy, over WiFi and mobile data too.
Android 6 changed some things related to SSL, could that be affecting it?
I was asked by XAMARIN suppport to install the beta version og their software and this "kinda" solved the issue. I can now consume a SOAP webservice, but the service cant be SSL encrypted, if you want to use android below 6.0.
So i removed the SSL encryption from our proxy and now it works with all versions!
I have a client who is implementing customer portals in Sharepoint 2013 Online. The current program distributes documents to the customers by mail. Now we have to upload the documents to the customer portal.
I try to use the copy webservice in sharepoint. I created a test project and added the webservice as Web Reference and wrote the following testcode:
static void Main(string[] args)
{
string baseUrl = "https://mycustomer.sharepoint.com/sites/";
string customer = "customerportalname";
string serviceUrl = "/_vti_bin/copy.asmx";
string destinationDirectory = "/folder/";
string fileName = "uploaded.xml";
string username = "username#outlook.com";
string password = "password";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<fiets><onderdeel>voorwiel</onderdeel><onderdeel>achterwiel</onderdeel><onderdeel>trappers</onderdeel><onderdeel>stuur</onderdeel><onderdeel>frame</onderdeel></fiets>");
byte[] xmlByteArray;
using (MemoryStream memoryStream = new MemoryStream())
{
xmlDocument.Save(memoryStream);
xmlByteArray = memoryStream.ToArray();
}
string destinationUrl = string.Format("{0}{1}{2}{3}", baseUrl, customer, destinationDirectory, fileName);
string[] destinationUrlArray = new string[] { destinationUrl };
FieldInformation fieldInfo = new FieldInformation();
FieldInformation[] fields = { fieldInfo };
CopyResult[] resultsArray;
using (Copy copyService = new Copy())
{
copyService.PreAuthenticate = true;
copyService.Credentials = new NetworkCredential(username, password);
copyService.Url = string.Format("{0}{1}", baseUrl, serviceUrl);
copyService.Timeout = 600000;
uint documentId = copyService.CopyIntoItems(destinationUrl , destinationUrlArray, fields, xmlByteArray, out resultsArray);
}
}
When I execute the code I recieve the following error:
The request failed with the error message:
--
<html><head><title>Object moved</title></head><body>
<h2>Object moved to here.</h2>
</body></html>
--
It looks like I'm not authenticated and get redirected. The credentials however are correct.
Does anyone have an idea? Thanks in advance!
UPDATE
To be able to connect to SharePoint 2013 Online you have to attach the Office 365 authentication cookies as explained in this post.
My problem however is that there is also an ADFS involved. How can I autheticate against the ADFS?
This error most probably occurs due to incorrect authentication mode.
Since SharePoint Online (SPO) uses claims-based authentication, NetworkCredential Class can not be utilized for authentication in SPO.
In order to perform the authentication against the ADFS in SPO you could utilize SharePointOnlineCredentials class from SharePoint Online Client Components SDK.
How to authenticate SharePoint Web Services in SharePoint Online (SPO)
The following example demonstrates how to retrieve authentication cookies:
private static CookieContainer GetAuthCookies(Uri webUri, string userName, string password)
{
var securePassword = new SecureString();
foreach (var c in password) { securePassword.AppendChar(c); }
var credentials = new SharePointOnlineCredentials(userName, securePassword);
var authCookie = credentials.GetAuthenticationCookie(webUri);
var cookieContainer = new CookieContainer();
cookieContainer.SetCookies(webUri, authCookie);
return cookieContainer;
}
Example
string sourceUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide.docx";
string destinationUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide 2013.docx";
FieldInformation[] fieldInfos;
CopyResult[] result;
byte[] fileContent;
using(var proxyCopy = new Copy())
{
proxyCopy.Url = webUri + "/_vti_bin/Copy.asmx";
proxyCopy.CookieContainer = GetAuthCookies(webUri, userName, password);
proxyCopy.GetItem(sourceUrl,out fieldInfos,out fileContent);
proxyCopy.CopyIntoItems(sourceUrl,new []{ destinationUrl}, fieldInfos, fileContent, out result);
}
References
Remote Authentication in SharePoint Online Using Claims-Based
Authentication
SharePoint Online Client Components SDK
In my case (on premise) i have that error. when i changed at iis SharePoint authentication for web application , and disable "Forms Authentication". Now, i canĀ“t enter to SharePoint by UI, but the Web Service works... So I have revert and I have been looking and...
[Paul stork] The Web Application for this site is running in Classic Mode rather than Claims mode. This can happen if you create the web app using Powershell or upgrade from 2010. You can use PowerShell to change it.
http://technet.microsoft.com/en-us/library/gg251985.aspx
I have tried the Web Service in another new application created by UI in Central Administration (in same farm) and it had worked. The problem was the web application.
To try:
http://sharepointyankee.com/2011/01/04/the-request-failed-with-the-error-message-object-moved-sharepoint-2010-web-services-fba/
Extend your mixed authentication web application, and create a zone just for Windows Authentication, then change the Web Reference URL in the properties of your web service, to use that extended URL and port. You should have no issues of this kind anymore.
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?