Example code for web portal

Hi,
I'm trying to get a simple query into a CRM server working 
from a web application.
It fails on the bizUser.WhoAmI call with a 401 not 
authorized error.

ANy clues as to what I need to do to get the web 
application authorized to do SOAP calls

Leo
0
Leo
7/2/2004 4:02:27 PM
crm 35858 articles. 1 followers. Follow

2 Replies
604 Views

Similar Articles

[PageSpeed] 45

Hi Leo:

You can try putting the directory the web application is loading from under 
the same directory as MSCRM, that way the web app is loaded from teh same 
security context.

Another way to do this is to explicitly set permissions:


// strServer should be set with the name of the platform Web server
string strServer = "your server name";

// strVirtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";
string strDir = "http://" + strServer + "/" + strVirtualDirectory + "/";

//===============================================================================
// Instantiate a System.Net.CredentialCache object.
System.Net.CredentialCache credentialCache = new 
System.Net.CredentialCache();

// Instantiate a System.Net.NetworkCredential object passing in the Active 
Directory UserName, Password and Domain that will be
//used to authenticate into the Microsoft CRM Security Model. This user 
needs to be setup in Microsoft CRM and
//given the appropriate License Keys and Roles.
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential 
("your user","your password","your domain");


// Add a value to the CredentialCache indicating the URI of the Microsoft 
CRM Server, "NTLM" which represents Integrated
//Windows authenticated and the credentials of the user to be used for 
authentication.
credentialCache.Add(new Uri("http://" + strServer), "NTLM", credentials);


//===============================================================================
// BizUser proxy object
Microsoft.Crm.Platform.Proxy.BizUser oBizUser = new 
Microsoft.Crm.Platform.Proxy.BizUser ();
oBizUser.Credentials = credentialCache;
oBizUser.Url = strDir + "BizUser.srf";


// CRMLead proxy object
Microsoft.Crm.Platform.Proxy.CRMLead lead = new 
Microsoft.Crm.Platform.Proxy.CRMLead ();
lead.Credentials = credentialCache;
lead.Url = strDir + "CRMLead.srf";

string strErrorMsg;
try
{
  Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = oBizUser.WhoAmI();
}
catch(System.Web.Services.Protocols.SoapException err)
{
  // Process the platform error here
  strErrorMsg = ("SoapException ErrorMessage: " + err.Message + " " + 
err.Detail.OuterXml + " Source: " + err.Source );
}
catch( Exception err )
{
  // Process other errors here
  strErrorMsg = ("Error ErrorMessage: " + err.Message + " Source: " + 
err.Source );
}
finally
{
  // Final code here
}

"Leo" <anonymous@discussions.microsoft.com> wrote in message 
news:2586001c4604d$f8bc8830$a301280a@phx.gbl...
> Hi,
> I'm trying to get a simple query into a CRM server working
> from a web application.
> It fails on the bizUser.WhoAmI call with a 401 not
> authorized error.
>
> ANy clues as to what I need to do to get the web
> application authorized to do SOAP calls
>
> Leo 


0
John
7/3/2004 1:38:50 PM
Thank you John that does the trick.
Now my XML query is failing! but that's another story....


Leo 
>-----Original Message-----
>Hi Leo:
>
>You can try putting the directory the web application is 
loading from under 
>the same directory as MSCRM, that way the web app is 
loaded from teh same 
>security context.
>
>Another way to do this is to explicitly set permissions:
>
>
>// strServer should be set with the name of the platform 
Web server
>string strServer = "your server name";
>
>// strVirtualDirectory should be set with the name of the 
Microsoft CRM
>// virtual directory on the platform Web server
>string strVirtualDirectory = "mscrmservices";
>string strDir = "http://" + strServer + "/" + 
strVirtualDirectory + "/";
>
>//========================================================
=======================
>// Instantiate a System.Net.CredentialCache object.
>System.Net.CredentialCache credentialCache = new 
>System.Net.CredentialCache();
>
>// Instantiate a System.Net.NetworkCredential object 
passing in the Active 
>Directory UserName, Password and Domain that will be
>//used to authenticate into the Microsoft CRM Security 
Model. This user 
>needs to be setup in Microsoft CRM and
>//given the appropriate License Keys and Roles.
>System.Net.NetworkCredential credentials = new 
System.Net.NetworkCredential 
>("your user","your password","your domain");
>
>
>// Add a value to the CredentialCache indicating the URI 
of the Microsoft 
>CRM Server, "NTLM" which represents Integrated
>//Windows authenticated and the credentials of the user 
to be used for 
>authentication.
>credentialCache.Add(new Uri("http://" + 
strServer), "NTLM", credentials);
>
>
>//========================================================
=======================
>// BizUser proxy object
>Microsoft.Crm.Platform.Proxy.BizUser oBizUser = new 
>Microsoft.Crm.Platform.Proxy.BizUser ();
>oBizUser.Credentials = credentialCache;
>oBizUser.Url = strDir + "BizUser.srf";
>
>
>// CRMLead proxy object
>Microsoft.Crm.Platform.Proxy.CRMLead lead = new 
>Microsoft.Crm.Platform.Proxy.CRMLead ();
>lead.Credentials = credentialCache;
>lead.Url = strDir + "CRMLead.srf";
>
>string strErrorMsg;
>try
>{
>  Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = 
oBizUser.WhoAmI();
>}
>catch(System.Web.Services.Protocols.SoapException err)
>{
>  // Process the platform error here
>  strErrorMsg = ("SoapException ErrorMessage: " + 
err.Message + " " + 
>err.Detail.OuterXml + " Source: " + err.Source );
>}
>catch( Exception err )
>{
>  // Process other errors here
>  strErrorMsg = ("Error ErrorMessage: " + err.Message + " 
Source: " + 
>err.Source );
>}
>finally
>{
>  // Final code here
>}
>
>"Leo" <anonymous@discussions.microsoft.com> wrote in 
message 
>news:2586001c4604d$f8bc8830$a301280a@phx.gbl...
>> Hi,
>> I'm trying to get a simple query into a CRM server 
working
>> from a web application.
>> It fails on the bizUser.WhoAmI call with a 401 not
>> authorized error.
>>
>> ANy clues as to what I need to do to get the web
>> application authorized to do SOAP calls
>>
>> Leo 
>
>
>.
>
0
anonymous
7/5/2004 8:41:17 AM
Reply:

Similar Artilces:

Can't open web links from recieved email
When I receive email containing web links, my cursor changes to the "hand w/finger". Up until recently, if I then "clicked" on that link, my "Micro Inter Explorer" would automatically open and take me to that website. Now, it has started to "lock up" the system. I then must, and I repeat must, "control, alt, delete" to bring up the "end program" box, but that completely shuts down my Outlook Express 6. Did I inadvertently change a setting? Is there a fix? Some incoming url's can be "copied" and "pasted to t...

Design Template for multithreading (an example here)
Multi threading multithreading multi-threading threading threads multitasking WaitOne .Set .Reset ManualResetEvent AutoResetEvent. Here is a design template you can use for multithreading. I prefer to use the manual reset event: ManualResetEvent rather than AutoResetEvent. It forces you to Set and Reset, and IMO is better than using the "automatic" way, which is more lazy. The design context is as follows: //put this mrevent outside your constructor, as a 'global' variable to the translation unit. public static ManualResetEvent mrevent = new ManualResetEv...

Lookup Codes
We are having some difficulties determinig a strategy for lookup codes. Specfically, we are trying to determine the best way to configure lookup codes for scalability, ease of data entry, as well ease of use at cash out. The customization for my POS system is a clothing boutique. We have scattered inventory, different venders from season to season, and limited stock for the items we do carry. I really wondering if its better to simply make lookup codes numeric, and print them out on our price tags. Is there some better strategy or approach to handling lookup codes? This is a multi...

Dont Close Web Site after entering a new suggestion!
Each time I post a suggestion, usually one of several, I have to log back on to post the next suggestion ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=f2a466c7-df36-44d7...

where to find mfc datagrid samples/code for vc++ 2005
Does anyone know where I can find some datagrid samples and code for MS VC++ 2005 using MFC and unmanaged code? I don't want older VC++ samples (ie 6.0 or .net 2003). support.microsoft.com/?kbid=229029 you should be able to add the functionality to your project after reading the sample. -- Regards Sheng Jiang Microsoft Most Valuable Professional in Visual C++ http://www.jiangsheng.net http://blog.joycode.com/jiangsheng/ "arch" <tony_ooooo@yahoo.com> д���ʼ� news:1157294966.36437@angel.amnet.net.au... > Does anyone know where I can find some datagrid samples and ...

List of Codes and Display Names for Codes #2
thanks that seems to be working thank you .... :) -- hoganc ------------------------------------------------------------------------ hoganc's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=14980 View this thread: http://www.excelforum.com/showthread.php?threadid=266031 ...

Examples of Add-ons
Does anyone have examples of add-ons for Visio? dave There is a full SDK for Visio complete with code examples on MSDN. The SDK for Visio 2003 is not yet available, but here is a link: http://msdn.microsoft.com/office/understanding/visio/ Meanwhile, look at the SDK for Visio 2002 and earlier here: http://msdn.microsoft.com/office/previous/visio/default.aspx -- Mark Nelson Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "dave" <shollas@shaw.ca> wrote in message news:u$YI1rz0DHA.208@TK2MSFTNGP12.phx.gbl... &...

WorkFlow
I made a simple web service that runs from a regular IE session no problem. However, when I run it through the Post URL action in Work Flow it errors out on the BizUser.WhoAmI Method. Has anyone ever experienced this problem before? Any help would be greatly appreciated. thx in advance - Gaurav Kalro ...

Business Portal Customizations #2
Hello Everyone, I have few questions on BP4 on MS Office SharePoint Server 2007 for GP10: 1) Is it possible to create a new business object using Web Services for GP SDK? If so can you please point me to some samples/learning resources on this? 2) I think its possible to load a custom aspx web page in BP using tab web part. Is it possible to determine the currently active company id/name and pass it on to such a web page as a parameter? 3) Is it possible to convert a custom aspx web page into a web part for BP - so that it can be added to the web part gallery? 4) I need to create a new...

Error Code 404 in server mgt concole
We installed SBS2003 Std and can coneect to the internet. In the magt concole of SBS, companyweb we are getting Error Code 404, File or Directory cannot be found. Can not connect to RWW form outside the domian. Sounds like the default website in IIS is not running. Usually a reboot will fix this, but if not, go into the IIS administration snap-in and start the default website. -Cliff "Kevin" <Kevin@discussions.microsoft.com> wrote in message news:242DA301-8C99-4BEE-BC1F-E9CCEE67AE6D@microsoft.com... > We installed SBS2003 Std and can coneect to the int...

Date based coding
Need a little help. I have a form that the users use to enter in vacation days onto a calendar. What I would like to do is allow them to make changes to this calendar but prevent them from changing things after the fact. Example if they were scheduled off on 11-16 they must change details for that date on or prior to the 16th. Is this possible? Hi Lori, to validate a record and prevent it from being saved, put code in the form BeforeUpdate event '----------------- make sure all required data is filled 'make sure SomeControlName is filled out If IsNull...

Visio 2003 Examples
There are some very good examples of what Visio 2003 can do available on the Microsoft Download site. Unfortunately they support the view that if you are serious about network support, Visio 2003 is content free and you will lose a significant amount of functionality by migrating from Visio 2002 with VENT. For the networking professional most of the networks support has been gutted from the new release..... al ...

need example code to get the contactID from SFA/conts/edit.aspx...
Hi!! My question is: How can I get the right ContactID from the current/opened Contact in Microsoft CRM? Can I read the ContactID out from the URL? Is there an example Code available? Microsoft�s SDK for CRM is not very helpful for this Problem. Has anybody already an example code? Thank you for your help! Greetings Daniel You should be able to get it from the query string, as long as you make sure that the entry in the isv.config file with the link to your app has the variable "PassParams" equal to 1 For example: <Button Title="Test" ToolTip="Info on Test&qu...

color coding events
I would like to color code events on my daily calendar and wonder if there is a way to change the color of text on individual events On 3/7/2010 6:27 AM, jcurtis wrote: > I would like to color code events on my daily calendar and wonder if > there is a way to change the color of text on individual events Which version of Outlook? Outlook 2007 introduced colored categories and I use them daily for color-coding events. Prior to Outlook 2007, colored labels were your option: http://office.microsoft.com/en-us/outlook/HP030848441033.aspx Additional information: htt...

Code to copy worksheet
Hi I'm sorry in advance - I'm a novice and I am stuck with re-writing the following code without using a hard code worksheet name, or "current worksheet" or "active worksheet" or "selection"... (I must avoid using these words as they are apparently causing problems macros assigned to buttons) The code needs to: - make a copy of the current worksheet - whose name appears in cell BP8 - put the copy into a separate workbook - select the named range "PlanCPTrange" on the copied worksheet (only) and paste special as values - select al...

Systray example
I want to create a helper app that controls the communcations port. The main application will load this helper when it the main app launches. I would like the helper to be in the background and I would like to install an icon on the systray. Does anyone know of a sample that may help get started? thanks This might help you: http://www.codeproject.com/shell/mfcstartup.asp Tom "mike" <nospamplease> wrote in message news:eslKtp7GGHA.648@TK2MSFTNGP14.phx.gbl... >I want to create a helper app that controls the communcations port. The >main application will load thi...

Problem with VBA code on command button
I have a form that has a combo box to select a month. The name of the combo box is txtmontha (I realise it would have been better to name it cmb???) The is a command button that when clicked should open a form where the date selected from the combo box is the same value as the date on the form. Here is the code behind the command button: Private Sub cmdopenrecord_Click() On Error GoTo Err_cmdopenrecord_Click Dim strqtr As String strqtr = Me.txtmontha.Value Forms!frmMain!SubForm1.SourceObject = "frmFDA" Forms!frmMain!SubForm1.Form.RecordSou...

Outlook Web Access automatically closeing its connection to your mailbox after a period of inactivity.
Does anyone know or Is there any way to increase the time of Outlook Web Access automatically closeing its connection to your mailbox after a period of inactivity. thanks ...

Example needed for gethostbyaddr Pwease =)
Hi :) My app needs to take a given IP and reverse (DNS) it to its machine name. I read a few articles on gethostbyaddr but I just cant get it to do anything except give me the ip back. Can someone show me how to reverse an IP address correctly? This is what I'm trying (keep in mind I'm in way over my head) :) VString address = "172.22.12.100"; struct hostent *pHost; pHost = gethostbyname(address); MessageBox(NULL, pHost->h_name, "test", MB_OK); Any code guru's out there wanna help a lady out? Thanks! char *arg = "a.b.c.d"; DWORD ip = inet_add...

Kirk Allen Evans---? how do I use your code to update my xmlDocument?
Kirk, The other day you very kindly explained how the client/server thing works. May I ask just one more question? Could you give me an example of what code I would put in the client html to post back the user input to the server xmlDocument? You gave me: One way is to use the Request.Form collection to read the values directly out of the post. System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Server.MapPath("data/xmlfile1.xml")); if(!IsPostBack) { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Server.MapPath("data/xmlfile1.xml&...

Error in "Home.aspx" code
After struggling with the error message that I inquired about below as well as some of those from other posts, I have discovered an error in the code of the home.aspx file. The problem is with the lines of code at the end of the file as shown below: <% //Call the method that will print a list of links to the respective entities this.PrintListOfEntities(); %></asp:Content> When opening the file with the Expressions application and placing your cursor on it, the message “In content pages, content...

TOM example
has anyone got any good examples of the Text Object Model? I'm using it with Rich Edit 2.0. in particular using: ITextRange->GetText() ITextRange->SetText() i've got the reference material from MSDN but could do with some examples of how to use these with CStrings especially. ...

Possible to save Excel as CSV with HTML codes?
Hi, I'm using Microsoft Office 2003. Some of my cells have formatting -- e.g. some words are bolded. Is it possible to save out my file as a CSV, but containing HTML codes for the formatted words? So for example, a cell saved to CSV might look like My <b>cell</b> because the word "cell" was bolded in my file? Thanks for any suggestions, - Dave Not if you just save it as a CSV file. This type of file is plain old text. On the other hand, you could create a macro that would do anything you wanted. You could start with code at these sites: Chip Pearson's:...

Excel : fill by example
Hi Is there a similar function to the Lotus 1-2-3 "fill by example". I've tried the Fill option under Edit, however can't seem to get it to work with dates. For example if I enter in 3 dates in a column (see example below), I would then like the next 20 or so rows for that column to be filled in with dates incrementing by one week. e.g 31.10.2005 07.11.2005 14.11.2005 thanks in advance. Steven If those are real dates and just formatted that way, you can select the top two cells. Click on the autofill button and drag down. Excel will see that you want to increm...

CODE EXAMPLE - Picklist
This is a multi-part message in MIME format. ------=_NextPart_000_00F2_01C402A6.D0E39920 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello All, I thought that I would try to initiate a code share system, ie any code = that you write if you think it would be useful to others please share... I know the code example below is a easy one to start with but it did = take a few tries before I got it right and we all know what a pain = carrying out code changes is with MSCRM. anyway hope this helps someone = out there... *****************...