私の組織 (ドメイン/Active Directory 環境の標準 Windows) では、1 つの Web サイトで複数の IIS アプリケーションと共に IIS 7.5 を使用するベンダー アプリケーションがあります。この製品の API を使用するには、追加の IIS アプリケーションを 1 つの Web サイトの一部として追加するインストール実行可能ファイルを実行します。インストールでは、basicHttp または Windows 認証が提供され、Windows を選択しました。
API (Get a Name サンプルの C# バージョン) を使用するための指示に従っています: http://www.documentation.newdawn.com/api/
Windows Visual Studio 2012 で C# コンソール アプリを作成し、[サービス参照の追加] メニュー項目を使用してサービス URL を使用し、クライアント クラスを作成しました。
URL のコードに対する私の唯一の変更は、BasicHttp の例の代わりに Windows 認証を使用することです。
using JustWareAPIClientConsoleApp.JustWareAPI;
namespace JustWareAPIClientConsoleApp
{
class Program
{
static void Main(string[] args)
{
JustWareApiClient client = new JustWareApiClient();
client.ClientCredentials.Windows.ClientCredential.Domain = "<domain>";
client.ClientCredentials.Windows.ClientCredential.UserName = "<username>";
client.ClientCredentials.Windows.ClientCredential.Password = "<password>";
Name n = client.GetName(123, null);
Console.WriteLine("Name: " + n.Last + "," + n.First);
client.Close();
Console.ReadLine();
}
}
}
App.config ファイルに変更を加えていません。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="JustWareApi" messageEncoding="Mtom">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://<server>/JustWareAPI/JustWareApi.svc"
binding="basicHttpBinding" bindingConfiguration="JustWareApi"
contract="JustWareAPI.IJustWareApi" name="JustWareApi" />
</client>
</system.serviceModel>
</configuration>
クライアント サンプルを実行すると、GetName メソッド呼び出しに到達したときに次のエラーが発生します。
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was ''.
Windows 認証の API インストール時の選択に基づいて、空白/null 値ではなく、「NTLM,Negotiate」のような応答ヘッダーを期待していました。
残念ながら、IIS についてはよくわかりませんが、API インストールが正しく設定されていないサイトまたはアプリケーション レベルの設定があり、有効な認証ヘッダーが返されないことがわかりました。このヘッダーがこのように戻ってくる理由を誰か教えてもらえますか?
ありがとう。