function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mnoorgatmnoorgat 

SharePoint Web Part with SalesForce

Hi,

I'm currently in the process of writing a web part for use in Microsoft SharePoint.

In order for me to allow my web part sufficient permissions to access web services I am required to create a customtrust.config file.

I'm hoping someone can help me with this as I am having problems.  If someone has any experience with this please post below and I'll state exactly the help I need.

One of the questions I have (which someone who hasn't developed with SharePoint can probably answer) is relating to what URI is accessed by the SalesForce API (v5.0)? In SharePoint (with custom trusts) I have to explicitly state the URI of the web service I need to access.  Below you can see what I'm using, does it seem correct?

                            <IPermission class="WebPermission" version="1">
                              <ConnectAccess>
                                <URI uri="https://www.salesforce.com/" />
                              </ConnectAccess>
                            </IPermission>

Thank you for your time.

DevAngelDevAngel

Right, so the url is shown in the wsdl and the generated proxy in .NET.  For north america it would be

https://na1-api.salesforce.com/services/Soap/c/5.0 .  This is for the enterprise wsdl on 5.0 of the api.  Your actual url may differ if you are using the Partner wsdl, are in an account that is homed on another appserver or are using a different version of the API.

mnoorgatmnoorgat

Thanks DevAngel,

Sorry for not posting an update - I wrote a long message going through everything I did step-by-step and my machine crashed before I could post!

I managed to get the correct url by running the following code (incidentally I could not find this url anywhere in the enterprise wdsl - I only found the second URL below):

txtBox3.Text=binding.Url; it was https://eu0-api.salesforce.com/services/Soap/c/5.0

What is: https://www.salesforce.com/services/Soap/c/5.0 as described in the WDSL used for?  Is the same url used to fetch data from salesforce?  If not how do I find this url?

Update: I can now successfully log into SalesForce through my webpart.  In order for me to do this I had to edit the trust.config which sharepoint was using (as described in web.config in the wwwroot folder).  A good description on how to do this can be found here: Microsoft Windows SharePoint Services and Code Access Security (scroll down to, How do I create a custom policy file?).

I didn't want to give my app Full permissions so had to specifiy exactly which permissions to give to it.

If anyone wants to know what permissions I had to use, just yell - the example link above tells you how to do it, just not exactly what you need to add for access to SalesForce.

In addition to adding the permissions in the .config file, I also had to add the following line to the sourcecode (before the namespace line):

[assembly:System.Security.AllowPartiallyTrustedCallersAttribute()]

The above is only necessary if you are not giving your code FullTrust permissions.

So far I can only log in successfully.  When I try to get data back via SOQL I get a permission error.  Seems to me like there is another URL I need to explicitly allow permission to.  I haven't had a chance to test out the second URL above yet.  Once I figure out what else is holding my web part back I'll be sure to report back.

Message Edited by mnoorgat on 03-28-2005 09:36 PM

DevAngelDevAngel

Hi mnoorgat,

You need to use 2 urls to interact with salesforce.com.  The first url, the one you have explicitly trusted, is for login and only for login.  As part of the response for a successful login, a url is returned in the serverUrl field of the loginResponse.  You need to repoint your SforceService to this url for all other calls.  This url will not change from session to session.  The one time it will change is if you generate a new wsdl after the API has been versioned, either a dot version or a full version.

It sounds like you are in Europe and that's why you are getting https://eu0-api.salesforce.com/services/Soap/c/5.0 in the login response.

In summary, all logins go to https://www.salesforce.com/services/Soap/c/5.0 (version 5.0 of the enterprise wsdl).  After login and before any other calls, you need to call binding.url = LoginResponse.ServerUrl to change the endpoint to the app server that services your data.  Don't forget to set the SessionHeaderValue on the binding to include the sessionId returned from your login call.

Cheers

mnoorgatmnoorgat

Thanks again Dave,

Your assistance, as always, is invaluable.  Yes I am in Europe, London, UK. =)

I think I'm missing something.  In Sharepoint I have given permission for my web part to access the following URLs:

"https://www.salesforce.com/.*" <-- Is this one necessary?
"https://eu0-api.salesforce.com/services/Soap/c/5.0/.*"

With this configuration I can only successfully login.  I can not access the data as it seems I am missing a permission for the "app server that services your data".

Please look at the following code for login:

   try
   {
    //execute the login placing the results
    //in a LoginResult object
    sforce.LoginResult loginResult = binding.login(txtUserName.Text, txtPassword.Text);
 
    //set the session id header for subsequent calls
    binding.SessionHeaderValue = new sforce.SessionHeader();
    binding.SessionHeaderValue.sessionId = loginResult.sessionId;
 
    //reset the endpoint url to that returned from login
    binding.Url = loginResult.serverUrl;
    lblStatus.Text = txtUserName.Text + " logged in successfully";
    txtBox1.Text= binding.Url; // binding.Url = "https://eu0-api.salesforce.com/services/Soap/c/5.0"
    return true;
   }

After login and before any other calls, you need to call binding.url = LoginResponse.ServerUrl to change the endpoint to the app server that services your data.

I think I am doing this correctly?

What do I need to type, and where, in order to find the app server which services my data (output to txtBox3)?

I'm not sure if I've made this clear (though it sounds like you already understand), my login code and accessing of data works fine when I use the same code as a standalone application running on my local machine.  My problem here is that I need to explicitly state in SharePoint which URLs I can allow my web part to access.

Thank you for your time,

Mohamed Imran Noorgat

SuperfellSuperfell
Its been a while since i've used sharepoint but https://eu0-api.salesforce.com/services/Soap/c/5.0/.* probably won't include https://eu0-api.salesforce.com/services/Soap/c/5.0 which is why its still not working. try changing the config to be
https://eu0-api.salesforce.com/services/Soap/c/.*
mnoorgatmnoorgat

Thanks Simon,

I will try that. On first glance I think you are correct.

I won't be able to report back the result for a while, but as soon as I can, I'll let you know.

Thanks again,

Mohamed Imran

PS. Is there a maximum number of logins which can be made concurrently by one user?

DevAngelDevAngel

Hi mnoorgat,

Yes, the maximum number of concurrent request per login is 3.

mnoorgatmnoorgat

Thanks Dave,

I wasn't very clear in my question I don't think, but you answered another one I had anyway. =)

Is there a limit to the number of times a user can login?  And is the max 3 request per login shared for that username over the many different login sessions, or is it seperate for each login session?

Mohamed Imran

DevAngelDevAngel

Hi mnoorgat,

It doesn't matter how many times you login, concurrent request are tracked by user (username).

mnoorgatmnoorgat

Thanks,

What will happen if > 3 concurrent requests are made?

Will it throw an UnexpectedErrorFault Exception, some other Exception or just wait and timeout?  (Trying to sort out my error handling).

Mohamed Imran