Accessing list from Sharepoint Webservice with Sharepoint Online 2013 - c#

I am trying to access a list from sharepoint via the web services.
I have tried lots of different web reference URLS for my web service.
The list is found at :
example.com/sites/dms/_layouts/15/start.aspx#/Lists/Documents/AllItems.aspx
the Web service URL I am using now is
https://example.com/sites/dms/_vti_bin/lists.asmx
Obviously example.com is not the real URL.
when I run the code
service.GetList("Documents");
I get the error:
List does not exist.
The page you selected contains a list that does not exist. It may have been deleted by another user.
0x82000006
My full code (many things are just for testing purposes):
public void UpdateList()
{
MKLists.Lists service = GetService();
string targetSite = "https://mywebpage.com/sites/dms";
using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite))
{
if (ctx != null)
{
ctx.Load(ctx.Web); // Query for Web
ctx.ExecuteQuery(); // Execute
string test = (ctx.Web.Title);
}
}
CookieCollection authCookie = ClaimClientContext.GetAuthenticatedCookies(targetSite, 925, 525);
service.CookieContainer = new CookieContainer();
service.CookieContainer.Add(authCookie);
XmlNode tester = service.GetList("Documents");
}
private MKLists.Lists GetService()
{
MKLists.Lists myService = new MKLists.Lists();
myService.Credentials = System.Net.CredentialCache.DefaultCredentials;
return myService;
}

change this line:
MKLists.Lists service = GetService();
with
MKLists.Lists service = new MKLists.Lists();
i hope this helps.
Edit
according to your comment in the answer here is the update #Michael
try changing your targetsite url to
string targetSite = "https://mywebpage.com/sites/dms/_vti_bin/Lists.asmx";
hope this time it helps

IT turns out it was to do with the subsites.. and this line solved it:
service.Url = "https://mywebpage.com/sites/dms/_vti_bin/lists.asmx";

I've found some users with the same issue.
They said that these links below solved that issue. Could you try it?
http://blogs.msdn.com/b/sharepointdev/archive/2011/05/12/connecting-to-sharepoint-online-web-services.aspx
http://www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx

Related

Web service consumption with oAuth2

AS you will see, I'm not an expert developing webApps, but I've done one that connects with the web services of Business Central (BC).
Inside visual studio, I added the web service as a service reference, and the authentication is user/password. This is how the call to the WS is done:
protected void ValidateEmployee()
{
var appSettings = ConfigurationManager.AppSettings;
string user = appSettings["user"].ToString();
string pswd = appSettings["pswd"].ToString();
string WHS_MGMT = appSettings["WHS_MGMT"].ToString();
string ItemTRacking = appSettings["ItemTRacking"].ToString();
WHS_MGMT ws = new WHS_MGMT();
ws.Credentials = new System.Net.NetworkCredential(user, pswd);
ws.Url = WHS_MGMT;
String codOperario = txtCodigo.Text.ToUpper();
string userPswd = txtPSWD.Text;
if (ws.Login(codOperario, userPswd))
{
Response.Redirect("Default.aspx?codOperario=" + codOperario);
}
else
{
lblOpIncorrecto.Text = "Operario/contraseƱa incorrecto";
lblOpIncorrecto.Visible = true;
}
}
But in nest weeks, we will be forces to use oAuth2 authentication to call BC web services. I've found several tips to get the token, and at first, doesn't seem to be a problem (at first...). But he main problem is that I don't know how to apply or use that token into the call to the WS. I even don't know it adding the WS as a service reference is the best way to do it...
Any tip will be realy welcomed
Thank you all

Why does SPContext.Current return a null value?

I am new in SharePoint development and I am developing a custom SharePoint Farm Solution. I am currently having an issue with code which runs properly on the production and test environments but gives an error on the development and I don't know why. The source code looks identical in all environments. I was able to locate the error through debugging and I found that it gives an error on the following line:
SPWeb web = SPContext.Current.Web;
The code is about sending an email upon the completion of course evaluation function in my application. Here's the code:
MailConfiguration config = new MailConfiguration();
MailNotification content = config.GetMailNotification(userId, courseId);
SPWeb web = SPContext.Current.Web;
string subject = content.Subject;
string msgBody = content.Body;
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
bool result = SPUtility.SendEmail(web, appendHtmlTag, htmlEncode, content.To, subject, msgBody);
message = "Email sent successfully";
});
Could you please explain to me why this is happening? The SendEmail function is not working now due to this error.
Check the follows:
1.Check the alternate mapping access(AAMs). If not, configure it.
2.Check if have Site Collection at the root of the SharePoint website.
3.Use the method below to create a fake SPContext in a non-SharePoint context.
public static SPContext FakeSPContext(SPWeb web)
{
if (HttpContext.Current == null)
{
HttpRequest request = new HttpRequest("", web.Url, "");
HttpContext.Current = new HttpContext(request, new HttpResponse(TextWriter.Null));
}
if (HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
{
HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
}
return SPContext.Current;
}

get the last modification date in a collection within sharepoint application

I have an asp.net Web Api application which communicates with a sharepoint application via web services.
I add this method to create a list reference with using http request
public static SPService.Lists CreateSPServiceListsReference(HttpRequestMessage request, bool defaultEpic = true)
{
var login = EpicConfiguration.ExtractAuthenticationParameters(request);
var lists = new SPService.Lists(){
Credentials = new NetworkCredential(login.Username, login.Password, login.Domain),
Url = string.Format(SPServiceListFormat, (defaultEpic)?login.EpicWebUrl:login.RefWebUrl)
};
return lists;
}
The this the first time I have to communicate with a sharepoint app. I need to call a service which takes as a parameter the name of the list and returns the last modification date in this this list. I googled before asking this question but I didn't find a solution.
Any ideas?
You could utilize Lists.GetList Method of SharePoint Web Services to retrieve schema for the specified list and then extract Modified property which represents last modified date.
Example
using (var svc = new ListsService.Lists())
{
svc.Credentials = new NetworkCredential(userName, password, domain);
var list = svc.GetList("Pages");
var listXml = XElement.Parse(list.OuterXml);
var lastModified = listXml.Attribute("Modified").Value;
}

PayPal Express Checkout SOAP API: Refunds

I use the PayPal Express Checkout SOAP service. For example here's a trimmed down version of the code to redirect the user to PayPal Sandbox when checking out:
var client = new PayPalAPIAAInterfaceClient();
var credentials = new CustomSecurityHeaderType() {
Credentials = new UserIdPasswordType() { ... }
};
var paymentDetails = new PaymentDetailsType() {
OrderTotal = new BasicAmountType() {
Value = string.Format("{0:0.00}", 100m)
}
};
var request = new SetExpressCheckoutReq() {
SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() {
SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType() {
PaymentDetails = new PaymentDetailsType[] { paymentDetails },
CancelURL = "http://www.mysite.com" + Url.Action("Cancelled", "PayPalCheckout"),
ReturnURL = "http://www.mysite.com" + Url.Action("Index", "PayPalCheckout")
},
Version = "60.0"
}
};
var response = client.SetExpressCheckout(ref credentials, request);
return Redirect(string.Format("{0}?cmd=_express-checkout&token={1}", "https://www.sandbox.paypal.com/cgi-bin/webscr", response.Token));
I then handle the data when the user is returned to the ReturnUrl. This was taken from some code I found on another website.
I now need to add a refund facility to my site. I was wondering if anyone else has done this? I've tried searching online but can't seem to find anything that helps. I also tried doing it myself but the API isn't very intuitive.
I'd appreciate the help. Thanks
It would just need to be a RefundTransaction API call that you would need to execute. Are you trying to have your return page issue a refund based on a condition, or are you trying to create a GUI type of interface to allow someone to issue a refund for a transaction? Have you looked at the code samples for this within the SDK's that PayPal offers? You should be able to use this code.

Facebook permission error

public Form1()
{
InitializeComponent();
// The application key of the Facebook application used
fbService.ApplicationKey = "XXXXXXXXXXX";
// Add all needed permissions
List<Enums.ExtendedPermissions> perms = new List<Enums.ExtendedPermissions>
{
Enums.ExtendedPermissions.none
};
fbService.ConnectToFacebook(perms); //error here (The given key was not present in the dictionary.)
}
I mention the error where I get the error , as am new to facebook api and specially new to c# any explained answer is appriciated
Thank you
Use the static method on FacebookClient like this:
FacebookClient.SetDefaultHttpWebRequestFactory(uri => {
var request = new HttpWebRequestWrapper((HttpWebRequest)WebRequest.Create(uri));
request.Proxy = ......; // normal .net IWebProxy
return request;
});
See this answer also: Facebook SDK Proxy setting C#

Categories