WCF サービス、wsHttpBinding および CustomBasicAuthentication があります。クライアントは Windows フォーム アプリケーションであり、指定されたユーザー名/パスワードで動作します。
ここで、HTML ページとなる別のクライアントを作成する必要があります。xmlHttpRequest を使用してサービスを呼び出そうとしていますが、次のエラーが発生します。
http://www.w3.org/2005/08/addressing/soap/faults:Sendera:BadContextTokenメッセージを処理できませんでした。これは、アクション 'http://tempuri.org/IService/SayHello' が正しくないか、メッセージに無効または期限切れのセキュリティ コンテキスト トークンが含まれているか、バインディング間に不一致があるためである可能性があります。非アクティブのためにサービスがチャネルを中止した場合、セキュリティ コンテキスト トークンは無効になります。サービスがアイドル セッションを途中で中止しないようにするには、サービス エンドポイントのバインディングの受信タイムアウトを早めに増やします。
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function CallServer() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://localhost:56779/BeSTService.svc', true,"umais","asghar");
xmlhttp.setRequestHeader("Content-type", "application/soap+xml");
var sr ='<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">'+
'<s:Header>'+
'<a:Action s:mustUnderstand="1">http://tempuri.org/IService/SayHello</a:Action>'+
'<a:ReplyTo>'+
'<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>'+
'</a:ReplyTo>' +
'</s:Header>'+
'<s:Body>'+
'<SayHello xmlns="http://tempuri.org/">'+
'<name>Umais</name>'+
'</SayHello>'+
'</s:Body>'+
'</s:Envelope>';
xmlhttp.send(sr);
}
</script>
</head>
<body>
<div style="margin:50px">
<input type="button" value="Call Service" onclick="CallServer();" />
</div>
</body>
</html>
また、Soap メッセージにセキュリティ ヘッダーを追加しようとしました。
'<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">' +
'<o:UsernameToken>' +
'<o:Username>umais</o:Username>' +
'<o:Password>asghar</o:Password>' +
'</o:UsernameToken>' +
'</o:Security>' +
しかし、同じエラー、Windows フォーム アプリケーションで IClientMessageInspector を使用する場合、送信される SOAP メッセージは、セキュリティ ヘッダーなしで、HTML で使用しているものとまったく同じです。
助けてください