Hello Hao,
The two-request behavior you saw is due to the authentication process of
windows intergated authentication, and this is a transport layer
authentication behavior rather than webservice code specific behavior.
When performing windows authentication, the client browser will send
request without authentication credential info, and if server-side require
user authentication, it deny the access and then a second request goes. So
far, one means for improve such authentication peformance is to se the
"PreAuthenticate" header of http request(webservice client proxy has a
property for this), however, only limited authentication scheme support
this "PreAuthenticate" setting. here is a webarticle which has mentioned
this:
#Web Service optimization
http://www.codeproject.com/soap/webserviceoptimization.asp
You can have a look to get more idea.
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hao - 19 Mar 2007 19:54 GMT
I've tried both PreAuthenticate to true and using the CredentialCache with
"Basic" schema. Only one messasge was sent, without the authentication
header, and therefore was rejected.
Any clue there? I also tried to override keepalive to either true or false,
did not make any difference.
Thanks.
Hao
> Hello Hao,
>
[quoted text clipped - 46 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Steven Cheng[MSFT] - 20 Mar 2007 07:14 GMT
Thanks for your reply Hao,
For the "PreAuthentication", if you're using basic authentication, it
require client-side supply the basic authentication based credential and
the server-side(IIS application virtual dir) is configured as basic
authentication). Have you configured the IIS virtual directory to use basic
authentication also?
And no matter set "PreAuthenticate" to true or false, the first request
will always send non authentication header which result a 401 error, and
the "PreAuthentication" setting will take effect for all sequential
requests (avoid the intial 401 roundtrip). You can refer to the following
MSDN document about the behavior of using "PreAuthenticate" property:
#HttpWebRequest.PreAuthenticate Property
http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.preauthen
ticate.aspx
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
> Just use CredentialCache instead of NetworkCredentials and the
> PreAuthenticate property in true.
Don't bother with PreAuthenticate. To make this work properly you will have
to override the GetWebRequest method in your client proxy.
Add something like this to your code (change "YourReference" to the name of
your Web Reference):
class OBACnetWSCore : YourReference.BACnetWSCore {
protected override WebRequest GetWebRequest(Uri uri) {
HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
NetworkCredential creds = Credentials as NetworkCredential;
if (creds != null) {
string authStr =
((creds.Domain != null) && (creds.Domain.Length > 0) ?
creds.Domain + @"\" : string.Empty) +
creds.UserName + ":" + creds.Password;
authStr = Convert.ToBase64String(Encoding.Default.GetBytes(authStr));
webRequest.Headers["Authorization"] = "Basic " + authStr;
}
return webRequest;
}
}
...and then use OBACnetWSCore for your proxy.
/Hans
Hans Liss - 31 Mar 2007 14:00 GMT
> > Just use CredentialCache instead of NetworkCredentials and the
> > PreAuthenticate property in true.
>
> Don't bother with PreAuthenticate. To make this work properly you will have
> to override the GetWebRequest method in your client proxy.
A comment, just to clarify: PreAuthenticate is what you want, it just
doesn't work properly. It causes the authentication header to be sent
automatically only on *subsequent calls*, never on the first one. The
homemade Authorization header technique i described above really is the best
way to do it right now, and let's just hope that Microsoft decides to
implement a proper PreAuthenticate behaviour sometime soon.
Please note also that, when *not* using this trick, in some situations
(talking with an Axis server, for instance) you will get a protocol error on
the second call, because there is something wrong with the .NET
implementation of HTTP 1.1. In these situations you will have to override the
GetWebRequest method anyway, to force it to use HTTP 1.0.
/Hans