Invoking WCF using JavaScript

Posted by Dnandha87 under WCF on 11/11/2011 | Points: 10 | Views : 2030 | Status : [Member] | Replies : 4
I have tried to invoke a wcf service using JAVA Script...
Script code is:
---------------------------
var xmlHttpReq =new ActiveXObject("Microsoft.XMLHTTP");
alert("hai");
//var content = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><ReverseName xmlns="http://tempuri.org/"><Name>nandha</Name></ReverseName></soap12:Body></soap12:Envelope>';
//<a:Action s:mustUnderstand="1">http://tempuri.org/IFunService/ReverseName</a:Action>
var content= '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo></s:Header><s:Body> <ReverseName xmlns="http://tempuri.org/"><Name>nandha</Name></ReverseName></s:Body></s:Envelope>';
xmlHttpReq.open("POST", "http://s9896/WCFTest/FunService.svc", false);
//xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpReq.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
xmlHttpReq.setRequestHeader ("SOAPAction", "http://tempuri.org/ReverseName");
xmlHttpReq.setRequestHeader("Content-Length", content.length);
alert(content);
xmlHttpReq.send(content);
alert(xmlHttpReq.responseText);
alert(xmlHttpReq.status);
alert(xmlHttpReq.statusText);

----------------------------

But i got an exception :
------------------------
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header><a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action></s:Header>
<s:Body>
<s:Fault>
<s:Code><s:Value>s:Sender</s:Value><s:Subcode><s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value></s:Subcode></s:Code>
<s:Reason><s:Text xml:lang="en-US">The message could not be processed. This is most likely because the action 'http://www.w3.org/2005/08/addressing/soap/fault' 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 .</s:Text></s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>
---------------------------

Am so confused with Security Context Token.. Can any one help me for ths problem?

Regards
Nandha Kumar,



Responses

Posted by: Blessyjees on: 11/11/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

Can you try after increase the value of receiveout in the binding configuration. You can see this in the we.config file.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Dnandha87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dnandha87 on: 11/11/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks for ur reply Blessy.
hamm.. I already done ths. but there was no use...
Do u know, how is Service settings in we.config file?
Iam using the below code.. Can u pls verify?

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IFunService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:60:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false" >
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message" >
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client >
<endpoint address="http://s9896.rsimail.rsil.ramco.com/WCFTest/FunService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFunService"
contract="FunServiceWCF.IFunService" name="WSHttpBinding_IFunService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service behaviorConfiguration="NameReverseWCF.Service1Behavior"
name="NameReverseWCF.FunService">
<endpoint address="" binding="wsHttpBinding" contract="NameReverseWCF.IFunService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="NameReverseWCF.Service1Behavior">
<!--To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment-->
<serviceMetadata httpGetEnabled="true"/>
<!--To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>


Regards
Nandha Kumar,

Dnandha87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/11/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

This is the configuration of the service project.
Where are you increasing the value. You need to increase this in the client that is where you add this service as reference.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Dnandha87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dnandha87 on: 11/11/2011 [Member] Starter | Points: 25

Up
0
Down
s. i had done these changes in the service project...
i couldnt find the receiveTimeout in the client web.confg...
Ths is the client web.config , am using:

<?xml version="1.0"?>
<configuration>
<appSettings >
<add key="ServiceWCF.Service" value="http://s9896.rsimail.rsil.ramco.com/SampleWCF/Service.svc" />
</appSettings>
<connectionStrings/>
<system.web>
<compilation debug="true"/>
<authentication mode="Windows"/>
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
</system.web>
</configuration>

Tell me where can i set the receivetimeout ?

Regards
Nandha Kumar,

Dnandha87, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response