Kamal_Kochar:I have an InfoPath form published in a SharePoint list which is connecting to UserProfileService.asmx
Are you using client or browser-based forms?
You should use either client (Infopath Filler 2010) forms or, if you use browser forms, then through the web proxy service for Infopath Form Services accessing while a web service cross-domain.
This is because Infopath browser-enabled forms communicate through stateless XMLHTTP protocol while Infopath client forms are using NTLM.
So, with Infopath browser-based form you have classic double hop authentication problem when the data connections/sources are in different other machines
Kamal_Kochar:It works fine in my stage server but when i moved it to development and production environment it gives me unauthorized 401 error while connecting to web service
Are your stage servers on the same machine?
Kamal_Kochar:1. One side it is giving me 'Unauthorized error', but on other it works sometimes (with same browser, on same machine)
What do you mean under the "One side" and the "other side". Your "other side" sounds to me like having no remote sides at all
"it works sometimes (with same browser, on same machine)" sounds like typical double hop authentication problem.
See my explanations above
Kamal_Kochar:This is driving me crazy because if some is unauthorized then how come he is able to connect sometimes.
"Some" probably doesn't connect at all but sees cached data.
Kamal_Kochar:2. It works fine in preview mode in InfoPath but gives error after publishing it to SharePoint site
This is because preview mode (and client forms) is connecting through NTLM while run-time browser forms through XMLHTTP.
The latter has double hop problem and the former does not.
Kamal_Kochar:4. I have tried giving explicit credentials in my data connection file
Once more, you should use the web proxy service while connecting to other servers (on other machines) from browser forms or connect from client (Infopath Filler 2010) to avoid double hop problem.
Kamal_Kochar:Note - I am using Windows Server 2008 R2 Standard edition and using NTLM authentication for my application
How have you configured and checked this?
You might want to use Wireshark or Fiddler to check authentication mechanism and how credentials are really passed
Kamal_Kochar:I am getting this error while browsing from any machine i.e server and other local machines
This is not only you, Everybodу else has the same issues and should configure their environment.
See my explanations above