Click here to Skip to main content
15,312,400 members
Please Sign up or sign in to vote.
4.00/5 (1 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:

" message could not be processed. This is most likely because the action '' 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" "">
<html xmlns="">
    <script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function CallServer() {
        var xmlhttp = new XMLHttpRequest();'POST', 'http://localhost:56779/BeSTService.svc', true,"umais","asghar");
        xmlhttp.setRequestHeader("Content-type", "application/soap+xml");
        var sr ='<s:Envelope xmlns:a="" xmlns:s="">'+
                    '<a:Action s:mustUnderstand="1"></a:Action>'+                    
                    '</a:ReplyTo>' +                        
                    '<SayHello xmlns="">'+
<div style="margin:50px">
    <input type="button" value="Call Service"  önclick="CallServer();" />

I have also tried adding Security Header in the Soap Message:
'<o:Security s:mustUnderstand="1" xmlns:o="">' +
    '<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

1 solution

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

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900