Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
We have a WCF service, wsHttpBinding and CustomBasicAuthentication. The Client is a Windows Forms application and it works with specified username/password.
 
Now we need to make another client, which will be calling the service from an html page. I am trying to call the service using xmlHttpRequest but getting following error:
 
"http://www.w3.org/2005/08/addressing/soap/faults:Sendera:BadContextTokenThe message could not be processed. This is most likely because the action 'http://tempuri.org/IService/SayHello' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding"
 
HTML page:
 
<!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"  önclick="CallServer();" />
</div>
</body>
</html>
I have also tried adding Security Header in the Soap Message:
'<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>' +
But same error, When using IClientMessageInspector in Windows Forms Application, the SOAP Message sent is exactly same as i am using in HTML, without Security Header
 
Please help
Posted 10-Jan-13 21:12pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is the article you need
Calling WCF Services using jQuery[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100