【发布时间】:2015-02-15 02:11:17
【问题描述】:
我的 Intranet 上有一个 Web 应用程序配置为在 IIS 上使用 Windows 身份验证。我们有一个 windows 网络和一个活动目录服务器,所以当一些用户尝试访问应用程序时,浏览器不会要求登录和密码,因为它使用当前登录用户的 windows 凭据。
我在此应用程序中添加了一个 Web 服务,并尝试在 Windows 应用程序中使用它。我尝试时收到错误 401。用户已经使用自己的凭据登录 Windows,所以我想让我的 Windows 应用程序使用当前用户的凭据登录到 Web 服务。
我的服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace MyWebServices
{
/// <summary>
/// Summary description for TestWS
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class TestWS : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
我的控制台应用程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyWebServiceClient
{
class Program
{
static void Main(string[] args)
{
TWS.TestWSSoapClient svc = new TWS.TestWSSoapClient();
try
{
Console.WriteLine(svc.HelloWorld());
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
}
finally
{
Console.ReadLine();
}
}
}
}
都是.net framework 4.5
对不起我的英语不好:)
【问题讨论】:
标签: c# web-services windows-authentication