質問編集履歴

3

「試したこと」にIISの設定内容を追記

2018/10/20 00:20

投稿

yukidaruma.
yukidaruma.

スコア13

test CHANGED
File without changes
test CHANGED
@@ -86,6 +86,12 @@
86
86
 
87
87
 
88
88
 
89
+ IISの設定は以下の通りです。
90
+
91
+ ![イメージ説明](88f8dee57061c2bc90b13a9e3305fac6.png)
92
+
93
+
94
+
89
95
 
90
96
 
91
97
  ### 補足情報(FW/ツールのバージョンなど)

2

「回答に対して試したこと」を追記

2018/10/20 00:20

投稿

yukidaruma.
yukidaruma.

スコア13

test CHANGED
File without changes
test CHANGED
@@ -105,3 +105,55 @@
105
105
  ■開発ツール:Visual Studio Professional 2017
106
106
 
107
107
  ■言語:C#
108
+
109
+
110
+
111
+ ### [追記]回答に対して試したこと
112
+
113
+
114
+
115
+ クレデンシャルを送る処理を追加しましたが同様の箇所でエラーが発生してしまいました。エラーメッセージは"Anonymous"の部分が"Negotiate"に変わりました。
116
+
117
+
118
+
119
+ ▼Windowsフォームアプリ
120
+
121
+ ```C#
122
+
123
+ private void button1_Click(object sender, EventArgs e) {
124
+
125
+ System.ServiceModel.BasicHttpBinding MyHttpBinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
126
+
127
+ MyHttpBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
128
+
129
+ System.ServiceModel.EndpointAddress MyAuthASMXWebServiceAddress = new System.ServiceModel.EndpointAddress(new Uri("http://localhost/SimpleAsmxWebService/SimpleWebService.asmx"));
130
+
131
+ SimpleWebServiceReference.SimpleWebServiceSoapClient cl = new SimpleWebServiceReference.SimpleWebServiceSoapClient(MyHttpBinding, MyAuthASMXWebServiceAddress);
132
+
133
+ cl.ClientCredentials.Windows.ClientCredential.Domain = "localhost";
134
+
135
+ cl.ClientCredentials.Windows.ClientCredential.UserName = "username";
136
+
137
+ cl.ClientCredentials.Windows.ClientCredential.Password = "password";
138
+
139
+
140
+
141
+ string value = cl.HelloWorld(); // ここでエラー発生
142
+
143
+ textBox1.Text = value;
144
+
145
+ }
146
+
147
+ ```
148
+
149
+ ▼エラー内容
150
+
151
+ ```
152
+
153
+ System.ServiceModel.Security.MessageSecurityException: 'この HTTP 要求は、クライアントの認証方式 'Negotiate' では承認されません。サーバーから受信した認証ヘッダーは 'Negotiate,NTLM' でした。'
154
+
155
+ 内部例外
156
+
157
+ WebException: リモート サーバーがエラーを返しました: (401) 許可されていません
158
+
159
+ ```

1

「試したこと」に不足情報を追記

2018/10/19 23:54

投稿

yukidaruma.
yukidaruma.

スコア13

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,72 @@
22
22
 
23
23
 
24
24
 
25
+ [IISの設定変更箇所]
26
+
27
+ Default Web Site内に作成した当該アプリケーションに対し[機能ビュー]から[認証]を開き、「Windows認証」のみ有効化し、その他は無効化しました。
28
+
29
+
30
+
31
+ ▼エラー内容
32
+
33
+ ```
34
+
35
+ System.ServiceModel.Security.MessageSecurityException: 'この HTTP 要求は、クライアントの認証方式 'Anonymous' では承認されません。サーバーから受信した認証ヘッダーは 'Negotiate,NTLM' でした。'
36
+
37
+ 内部例外
38
+
39
+ WebException: リモート サーバーがエラーを返しました: (401) 許可されていません
40
+
41
+ ```
42
+
43
+ ▼Webサービス(自動生成されたコメント部を省いています)
44
+
45
+ ```C#
46
+
47
+ [WebService(Namespace = "http://localhost")]
48
+
49
+ [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
50
+
51
+ [System.ComponentModel.ToolboxItem(false)]
52
+
53
+ public class SimpleWebService : System.Web.Services.WebService {
54
+
55
+ [WebMethod]
56
+
57
+ public string HelloWorld() {
58
+
59
+ return "Hello World";
60
+
61
+ }
62
+
63
+ }
64
+
65
+ ```
66
+
67
+ ▼Windowsフォームアプリ
68
+
69
+ ```C#
70
+
71
+ private void button1_Click(object sender, EventArgs e) {
72
+
73
+ SimpleWebServiceReference.SimpleWebServiceSoapClient cl = new SimpleWebServiceReference.SimpleWebServiceSoapClient();
74
+
75
+ string value = cl.HelloWorld(); // ここでエラー発生
76
+
77
+ textBox1.Text = value;
78
+
79
+ }
80
+
81
+ ```
82
+
83
+ ブラウザからWebサービスにアクセスした場合は以下の通り表示されます。
84
+
85
+ ![イメージ説明](9d142f53d2f33ae55df8a05cba3b4692.png)
86
+
87
+
88
+
89
+
90
+
25
91
  ### 補足情報(FW/ツールのバージョンなど)
26
92
 
27
93