Exception occurred: The request failed with http status 401: Unauthorized

Jul 30, 2008 at 11:05 AM
Edited Jul 31, 2008 at 4:19 AM
Hi,

I'm getting a 401 error following the example from page 10 of the word document, "Run a WebTest", "CreateNewNoteForAccount".

Here's the details

System.Exception: Exception occurred: The request failed with HTTP status 401: Unauthorized.

   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at AppGridWebService.AppGridWebService.Reset(String gridXml, String id) in C:\CRM 4.0 Toolkit\CRM4_Perf_Toolkit\CRM_Perf_BenchMark\WSDL\AppGridWebService.cs:line 54
   at CRM_Perf_BenchMark.CreateNewNoteForAccount.<GetRequestEnumerator>d__0.MoveNext() in C:\CRM 4.0 Toolkit\CRM4_Perf_Toolkit\CRM_Perf_BenchMark\WebTests\CreateNewNoteForAccount.cs:line 131
   at Microsoft.VisualStudio.TestTools.WebStress.WebTestCaseVariation.ExecuteNextTopLevelRequest()





Jul 31, 2008 at 4:07 AM

Here's the screen shot 

HTTP 400
Aug 6, 2008 at 8:02 PM
Hi,
 Is the user who is being used to run the test have create permissions to create a contact? Best way to check is to try to create an account from the application directly through the IE window. 
When you ran the first time, did EntityManager copy the data from the CRM SQL server correctly? Best way to ensure that is to open EntityManager database, goto table systeminfo and clear all the information in it, by running "Truncate table systeminfo" and then rerun a simple test such as CreateNewAccount.cs and then ensure all data is copied correctly into EntityManager database without any exceptions. Once EntityManager database is populated correctly, then ensure all the users you are running the tests as are have proper permissions to talk to CRM server. Looks like the user being used to run the test as does not have proper permissions to talk to CRM server in the first place.

Thanks,
 Adi.
Aug 7, 2008 at 6:11 AM
Edited Aug 7, 2008 at 7:05 AM
Hi Adivarma,

Thanks for the quick response.

To answer your questions.

>>  Is the user who is being used to run the test have create permissions to create a contact? Best way to check is to try to create an account from the application directly through the IE window.

The data was populated using the RunPopulation.cmd. Even though only a single test user account has been created for this performance test, I believe all test users will be granted the "SA" role by the script.

I've verified the test user account to have been granted the "SA" role in MSCRM by the script. Logging in MSCRM using the Test User account, I'm able to create an account or contact with no errror.

I deactivated all contacts owned by the test user before running the webtest. Although VSTS is throwing a 401 error, a new contact got created.

In addition, running the webtests in debug mode, the exception is thrown when it attempts to execute the AppGridWebService.Refresh or AppGridWebService.Reset. Again, using the test user account, I can verify the test user account able to access the WebService.

>> When you ran the first time, did EntityManager copy the data from the CRM SQL server correctly? Best way to ensure that is to open EntityManager database, goto table systeminfo and clear all the information in it, by running "Truncate table systeminfo" and then rerun a simple test such as CreateNewAccount.cs and then ensure all data is copied correctly into EntityManager database without any exceptions. Once EntityManager database is populated correctly, then ensure all the users you are running the tests as are have proper permissions to talk to CRM server. Looks like the user being used to run the test as does not have proper permissions to talk to CRM server in the first place.

I can verify the data got copied into EntityManager after running EMDBLoader.exe. I'm not sure whether it was done "correctly". Will look into this on my next visit onsite.

Following the steps provided on page 10 of the supporting document, I'm not seeing any error messages or out of the ordinary from dbmon.exe when the webtest was executing.



Aug 7, 2008 at 6:47 AM
Edited Aug 7, 2008 at 6:49 AM
Hi Adi,

FYI. I got a reply from Russ Dobbins earlier on.

The followings is the extract of my email to him. Could it have anything to do with the setup? The scripts or webtests not able to support clustered or load balancing?

=======================================

The Customer requested the performance load tests to be conducted in production or live environment.

Configuration as follows
- All Servers running Windows 2003 R2 x64. Fully patched up.
- 3 x MSCRM 4.0 Servers. Utilizing Win2003 server software network load balance feature.

·         Xeon Quad Core 3 GHz

·         8 GB RAM

·         2x73 GB (RAID 1)

- 2 x SQL 2005 Servers. Clustered (Active/Passive)

·         Xeon 4 Way Quad Core 3 GHz

·         32 GB RAM

·         2x73 GB (RAID 1) ~ OS

- 1 x SQL Report Server
- 1 x SharePoint/Performance Point Server
- Internet Explorer 6.0 instead of 7.0 due to organization policy.
 
A single test user account (crmuser1) has been created for the load tests. The data was populated via the script provided by the toolkit. The SA role is granted to the test user (crmuser1), as per default.
 
It was not a VSTS recorded webtest. The "CreateNewContact" webtest script provided by the Toolkit was used. As seen from the screen shot, "200" when loading the pages, "401" when editing or creating. BTW, the Contact got created successfully.
 
The CrmUser1 account has been tested to be able to access and create new contacts and others via WebClient.
 
Could it have something to do with the error on the Discovery Service during the toolkit installation? Refer Error:Discovery server name is missing

Aug 7, 2008 at 10:26 PM
No,
 The discoverServer name is missing should be fine as it defaults to CRM Server machine. I am assuming your discoveryserver and Crm Server are the same box.

Can you give this a shot:
Open crm server and open up MSCRM registry key. The path is
HKLM -> SOFTWARE -> Microsoft -> MSCRM

Create a new dword Registry value called "IgnoreTokenCheck" and set its value to 1.

Then rerun the test. I am doubtful but let us see if this rectifies the problem.

Thanks,
 Adi.
Aug 7, 2008 at 10:36 PM
Best way is to see how the webtest is different from the actual call. You can do this by running fiddler tool to capture the traffic between the client and crmserver. You can get it from www.fiddler2.com

Run the same clicks from IE and capture the fidder trace and compare what it sends with what is being sent in webtest for the failing request. You will be able to get a better idea of the reason that way.
Aug 8, 2008 at 7:18 AM
Edited Aug 11, 2008 at 9:39 AM
Hi Adi,

Appreciate the follow up. Will give "fiddler2" and "ignoretokencheck" a try on my next trip onsite.

I was onsite yesterday. As instructed, I truncated the systeminfo table and executed the "CreateNewAccount" webtest. The new account was created in both MSCRM and the account table in EntityManager DB. dbmon.exe reported a series of "Didn't effect 1 row" prior to the output "Reading 10 security roles". Is that something to worry about?

The local engineer observed something peculiar on the IIS log. These entries was captured during execution of "CreateNewFax" webtest provided by the toolkit.

As highlighted, each requests had been fired twice.
- In red, without passing credential (ABCHQ\crmuser1) => 401.2,
- With credential (ABCHQ\crmuser1)  =>  200. 

Is there a minimum number of test user accounts required for use by the toolkit? As indicated in my previous posts, a single test user account (ABCHQ\crmuser1) has been created for the test.

2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/Workplace/home_activities.aspx - 80 - 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 401 2 2148074254 266 255 15
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/Workplace/home_activities.aspx - 80 ABCHQ\crmuser1 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 200 0 0 11316 3955 171
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/Activities/dlg_create.aspx - 80 - 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 401 2 2148074254 266 227 0
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/Activities/dlg_create.aspx - 80 ABCHQ\crmuser1 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 200 0 0 3791 3951 15
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/activities/fax/edit.aspx - 80 - 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 401 2 2148074254 266 225 15
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/activities/fax/edit.aspx - 80 ABCHQ\crmuser1 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 200 0 0 12650 3949 93
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/_forms/FormScript.js.aspx etc=4204&FormType=main&FormName=crmForm 80 - 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - http://ecin.abc.com.sg/abc/activities/fax/edit.aspx ecin.abc.com.sg 401 2 2148074254 266 328 0
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/_forms/FormScript.js.aspx etc=4204&FormType=main&FormName=crmForm 80 ABCHQ\crmuser1 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - http://ecin.abc.com.sg/abc/activities/fax/edit.aspx ecin.abc.com.sg 200 0 0 547 4052 15
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/_controls/lookup/lookupsingle.aspx class=ActivityRecipient&objecttypes=1%2c2%2c4%2c8%2c2020&browse=0&ShowNewButton=1&ShowPropButton=1&DefaultType=0 80 - 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 401 2 2148074254 266 348 0
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 GET /abc/_controls/lookup/lookupsingle.aspx class=ActivityRecipient&objecttypes=1%2c2%2c4%2c8%2c2020&browse=0&ShowNewButton=1&ShowPropButton=1&DefaultType=0 80 ABCHQ\crmuser1 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - - ecin.abc.com.sg 200 0 0 10077 4072 46
2008-08-07 09:47:40 W3SVC1 DUMMY 10.15.99.99 POST /appwebservices/appgridwebservice.asmx - 80 - 10.15.199.110 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.42) - - ecin.abc.com.sg 401 2 2148074254 266 1819 0
Aug 11, 2008 at 9:38 AM
Here's the output from dbmon.exe

1140: Read 21 BusinessUnits
1140: Read 1000 Lead (More to Come)
1140: Read 2000 Lead (More to Come)
1140: Read 2113 Leads
1140: Read 711 Opportunities
1140: Read 36 Accounts
1500: [Winlpd Service](1568): My service is sleeping (348088)...
1140: Read 1000 Contact (More to Come)
1140: Read 2000 Contact (More to Come)
1140: Read 2082 Contacts
1140: Read 75 Appointments
1140: Read 960 Emails
1140: Read 75 Faxes
1140: Read 75 Letters
1140: Read 76 Phonecalls
1140: Read 302 Tasks
1140: Read 41 Subjects
1140: Read 1 Services
1140: Read 1000 Quote (More to Come)
1140: Read 1050 Quotes
1500: [Winlpd Service](1568): My service is sleeping (348089)...
1140: Read 315 Roles
1140: Read 255 Incidents
1140: Read 1000 Annotation (More to Come)
1140: Read 2000 Annotation (More to Come)
1140: Read 3000 Annotation (More to Come)
1140: Read 4000 Annotation (More to Come)
1500: [Winlpd Service](1568): My service is sleeping (348090)...
1140: Read 5000 Annotation (More to Come)
1140: Read 6000 Annotation (More to Come)
1140: Read 6112 Notes
1140: Read 54 Campaigns
1140: Read 5 PriceLevels
1140: Read 59 Lists
1140: Read 1000 ServiceAppointment (More to Come)
1140: Read 2000 ServiceAppointment (More to Come)
1140: Read 2700 ServiceAppointments
1140: Read 486 Privileges
1140: Read 60 Equipment
1140: Read 52 Reports
1140: Read 1 Currencies
1140: Didn't effect 1 rowDidn't effect 1 rowDidn't effect 1 rowDidn't effect 1 r
owDidn't effect 1 rowDidn't effect 1 rowDidn't effect 1 rowDidn't effect 1 rowDi
dn't effect 1 rowDidn't effect 1 rowRead 10 Systemuserroles
1140: Elapsed Time: 00:00:03.7187024
Aug 11, 2008 at 10:33 AM
Edited Aug 11, 2008 at 10:39 AM
Setting "IgnoreTokenCheck" to 1 doesn't rectify the problem.

Here's a screen shot where the exception is  thrown
Photobucket 

Exception Detail
System.Net.WebException was unhandled by user code
  Message="The request failed with HTTP status 401: Unauthorized."
  Source="System.Web.Services"
  StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at AppGridWebService.AppGridWebService.Refresh(String gridXml) in C:\CRM 4.0 Toolkit\CRM4_Perf_Toolkit\CRM_Perf_BenchMark\WSDL\AppGridWebService.cs:line 98
       at CRM_Perf_BenchMark.CreateNewAccount.<GetRequestEnumerator>d__0.MoveNext() in C:\CRM 4.0 Toolkit\CRM4_Perf_Toolkit\CRM_Perf_BenchMark\WebTests\CreateNewAccount.cs:line 160
       at Microsoft.VisualStudio.TestTools.WebStress.WebTestCaseVariation.ExecuteNextTopLevelRequest()
Aug 15, 2008 at 11:15 AM
HELLO? Anybody home?
Aug 15, 2008 at 8:39 PM
Oh,
 I think i know the problem. Can you check up on the file, VSTestHost.exe.config file in the Program Files\Microsoft Visual Studio 8\Common7\IDE folder.
This file should have a node as follows:

<appSettings><add key="urlkey" value="crm://[YOUR WEB SERVER]/"/></appSettings>

as a child of <configuration>

If it is not there, the webservice request is going directly to the webserver which we don't want to happen. We want to throw a crmexception, catch it, manipulate it to get the correct request going to the webserver.

Let me know.

Thanks,
 Adi.
Aug 16, 2008 at 3:07 PM

Hi,

 

In case relevant - we have not been able to get the toolkit to working with Forms Authentication.

We have also found that in our setups we have had to manually add/change the vstesthost.exe.config to get things working - (this took an age to figure out!) - is there a case for adding this to the documentation (I don't remember it beng mentioned there)?

In regards to the two requests (an unauthorised request first) - I have seen this when it has been working - a little concerned it is working in this way - but didn't appear to have much of an impact on performance - in anycase would be good of someone could clarify is this is expected behavour - I can understand why it may be happening - but its one of those findings that leaves a question mark on things!
 (perhaps a different discussion this?)

Andy


 

 

Aug 18, 2008 at 8:09 AM

Hi Adi,

Yes. That resolved the 401 error. Thank you for all your hardwork and the CRM Product Team for coming up with this toolkit.

It had been a wonderful ride.

Regards,

Aug 18, 2008 at 8:12 PM
Hi,
 That is odd. The msi should automatically update the vstesthost.exe.config file with the relevant data. That is why I did not add that to the documentation. I am wondering if the msi was installed by a user account which did not have write privileges to manipulate the config file and msi installation takes that as silent non stopping failure. I will add this to the documentation. Thanks for the feedback guys and I apprecieate any future improvement suggestions that can ease your experiance for the next release.
thanks,
 Adi.
Aug 19, 2008 at 8:45 PM

hmmm

I will pay more attention to this the next time i do a fresh install and check to see if it gets updated.

Additionally we have had to point CRM at a diferent URL (different SUT's but same load generator) - so in this case it will have to be modified unless its just a different CRM Organisation, you could perhaps include in documentation somewhere with the configsetiings.xml where you can alter the server names/URLs - it would then be mentioned and others will know its there will help

We have had failed installations - and then retried successfully - I wonder if this was anything to do with it...

Thanks