Transferred from: http://www.cnblogs.com/geqinggao/p/3270499.html
Recent projects require Web Service authentication authorization, and there are generally two solutions:
1. Pass through SOAP header authentication.
2. Through Integrated Windows authentication.
I tried it today. The second way to authorize is to first publish the Web service to IIS, then select Authentication, enable Windows Authentication, disable anonymous authentication
Publish the Web servive will be called on the client side, I use VS2008, in the client side project reference right-click Add Service Reference, enter address modify namespace OK
The next step is to write the background calling code:
Multiple authorizations have been attempted, and HTTP requests are always reported without the client authentication scheme "Anonymous" authorization. The authentication header received from the server is "NEGOTIATE,NTLM". The wrong, very no solution ah!
Think it's because. NET 3.5 has compatibility issues with 2.0 Web service by adding service references (WCF references)? Honestly, add the Web service in a WS2005 way and try again:
Because Windows authentication is enabled when publishing a Web service, all references will prompt you for a comfortable user name and password, and the following page is the true "add Web Reference" instead of "Add a service Reference"
Next Backstage code:
private
void
button1_Click(
object
sender, EventArgs e)
{
XmlNode x =
null
;
WSPTIClient.PTIWS.PTIWebService s =
new
WSPTIClient.PTIWS.PTIWebService();
s.Credentials =
new
System.Net.NetworkCredential(
"Gerry"
,
"password"
);
x = s.Transight_RetrieveOrder(1, DateTime.Now.Date,
"-1"
);
MessageBox.Show(x.OuterXml);
}
|
Run no error, everything OK. Let's see more references to the project. Add a Web Reference
Reference: http://developer.51cto.com/art/200908/141829.htm
HTTP requests are not authorized by the client authentication scheme "Anonymous". The authentication header received from the server is "NEGOTIATE,NTLM"