401 unauthorized exception while reading data from the document library SharePoint 2010 - sharepoint-2010

We developed a WebPart to read the content of the file in the document library in the SiteCollection. I used the following code to read the content.
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultNetworkCredentials;
string documenturl = siteurl+"/" + file.Url.ToString();
content = wc.DownloadData(documenturl);//documenturl is the file path of the document
But, i got the following error 401 unathorized exception
System.Net.WebException: The remote server returned an error:(401) Unauthorized. at System.Net.WebClient.DownloadDataInternal(Uri address,WebRequest& request) at System.Net.WebClient.DownloadData(Uri address)
For your information, i already tried to download document by SPFile openBinary method. But it only works when the document is small. Please refer the below site.
getting ComException while reading the document in SharePoint 2010
Thanks in advance.

Probably the local loopback check. (Verify by trying to access your site using the same URL whilst using IE running on your SharePoint server)
Also - any reason why you're using web services to access local content rather than the SharePoint object model (Microsoft.SharePoint.dll)?

Related

.NET Core 6 API Access SharePoint Online but Http Error 403

To download file from SharePoint Online, I tried to access it by .NET Core 6 Web API CSOM and here is my sample code.
using Microsoft.SharePoint.Client
private void DownloadFileFromSPO()
{
string site = "https://domain.sharepoint.com/sites/xxx";
string user = "userID";
SecureString securePwd = new SecureString();
string password = "passward";
foreach(char c in password.ToCharArray())
{
securePwd.AppendChar(c);
}
using (ClientContext context = new ClientContext(site))
{
context.Credentials = new NetworkCredential(user, securePwd);
Microsoft.SharePoint.Client.File file context.Web.GetFileByUrl(fileUrl);
context.Load(file);
context.ExecuteQuery();
//do something
}
}
}
Unfortunately, when I called this method but got a http error 403: FORBIDDEN. Refer to this article, error 403 means server telling you, “I’m sorry. I know who you are–I believe who you say you are–but you just don’t have permission to access this resource.
So I supposed my API was trying to access correct website with correct userID and passward, but do not have authentication to access it. I also found there were many articles suggest replacing NetworkCredential(user, securePwd); by SharePointOnlineCredentials (user, securePwd);. However, when I tried this solution, I found my installed CSOM package did not have this class.
I also found MS docs said SharePointOnlineCredentials is not available anymore, they recommend another "OAuth access token" way to get the authentication.
My question is, is that the only way to get the authentication to access SharePoint Online? Due to company policy, configuring an application in Azure AD process is bothering me. Is there another solution, just by code and package, in this scenario?

405 Method Not Allowed - Dynamics GP 2010 Web Service

I am trying to access my client's GP 2010 web service, but I get this error:
The request failed with HTTP status 405: Method Not Allowed.
The URL is http://www.xyz.com:48620/Dynamics/GPService
In Visual Studio, I see this URL in the add web reference box:
xyz:48620/Metadata/WCF/Full/schemas.microsoft.com.dynamics.gp.2010.01.wsdl
When I visit the URL in the browser, I can see the WSDL:
Here is the WSDL code:
http://pastebin.com/0VU7ZRbE
The customer has installed the GP2010 web service and it appears in the browser. I cannot add a reference to it in Visual Studio. The customer has added an inbound and an outbound firewall rule.
Am I using the wrong URL or is there something else to install?
When you add a web reference, you add localhost:48620/Dynamics/GPService . If you need to authenticate to another one, add change the URL:
// Create an instance of the service
DynamicsGP.Core.DynamicsGPService.DynamicsGP wsDynamicsGP = new DynamicsGP.Core.DynamicsGPService.DynamicsGP();
wsDynamicsGP.Url = "http://www.mysite.com:48620/DynamicsGPWebServices/DynamicsGPService.asmx";
// Be sure the default credentials are used
wsDynamicsGP.UseDefaultCredentials = true;
wsDynamicsGP.Credentials = new NetworkCredential("username", "password", "domain");
CompanyCriteria cc = new CompanyCriteria();
Company[] c = wsDynamicsGP.GetCompanyList(cc, new Context());
return wsDynamicsGP;

Do not comment shaerpoint's Lists.asmx service

I am trying to fetch the list of file names which are there in my document library of office 365 SharePoint site.
I am using below code to access the List.asmx Service using Visual Studio 2010.
ServiceReference1.ListsSoapClient ws = new ServiceReference1.ListsSoapClient();
ws.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("USERNAME", "PASSWORD", "sharepoint");
ws.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://XYZ.sharepoint.com/_vti_bin/lists.asmx");
XElement li = ws.GetListCollection();
This code gives me below error while executing ws.GetListCollection() function:
The HTTP request was forbidden with client authentication scheme 'Ntlm'.
Can anyone help me that? Is there any problem on SharePoint site access permissions or am I missing something in code part or some configuration things?

How do I call a WCF service from RestSharp

Can someone post some sample code to access a WCF service from RestSharp. I am trying to get data into a MonoDroid application and RestSharp seemed pretty simple. However I cannot seem to find any sample code which works. I have hosted the WCF service on my website under shared hosting. I have posted the RestSharp code I am using below but I am getting an error.Can someone tell me what I am doing wrong here
var client = new RestClient("http://mysamplesite.com/testService");
// client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest("gettestdata", Method.GET);
request.AddParameter("key", "");
// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
if (!string.IsNullOrWhiteSpace(response.Content) && response.StatusCode == System.Net.HttpStatusCode.OK)
DeserialiseData(content);
Server Error in Application \"MYSAMPLESITE.COM/TESTSERVICE\"
Internet Information Services 7.5
Error Summary
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Detailed Error Information
IIS Web Core Error Code 0x80070002
Requested URL http://www.mysamplesite.com:80/TestService/GetTestData
Physical PathD:\rwq1 \n
Logon MethodAnonymous \n Logon UserAnonymous \n
Most likely causes: \n \t
The directory or file specified does not exist on the Web server.
The URL contains a typographical error

How does one publish a map to the web?

Just starting out with ArcGIS server at work, I've had no prior experience but I been given the responsibility to display our map on the web.
I have a ArcGIS server running on a server and I am using ArcMap 10 on my desktop. I created a Folder in the server where I saved the map document. I can add a new service using this document and I'm given a url when I do so. But when I go to that URL I get this error:
Server Error in '/ArcGIS/Services' Application.
Runtime Error
And, when going to the same url from the server I get:
Server Error in '/ArcGIS/Services' Application.
No Content
Do you try to open servername/ArcGIS/services via browser? This url is for SOAP requests, e.g. you can add '?wsdl' to it ang get SOAP service description. To use it with browser you'll need ArcGIS Server REST API, i.e. use 'servername/ArcGIS/rest/services' URL.