hello

1. On WCF Service side (IIS hosted WCF), I've configured an endpoint
(i.e. WCF Web.config).

<services>
<service behaviorConfiguration="ServiceBehavior"
name="xxxxx.XXXXXServiceLib.XXXXXService">
<endpoint address="MEX" binding="mexHttpBinding" name="MEX"
contract="IMetadataExchange" />
<endpoint address="JSON" behaviorConfiguration="JSONBehavior"
binding="webHttpBinding" bindingConfiguration="" name="JSON"
contract="xxxxx.xxxxxServiceLib.ISecurityService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/XXXXXServiceWeb/XXXXXService.svc"; /
>
</baseAddresses>
<timeouts closeTimeout="00:01:10" />
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JSONBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>


2. ASP.NET server side calls this WCF with this endpoint defined in
its web.config.

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="JSONBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings />
<client>
<endpoint address="http://localhost/XXXXXServiceWeb/XXXXXService.svc/
JSON"
behaviorConfiguration="JSONBehavior" binding="webHttpBinding"
bindingConfiguration=""
contract="XXXXXServiceReference.ISecurityService"
name="JSON" />
</client>
</system.serviceModel>

Now, it works very well! The user hit the button on the ASP.NET page,
which causes ASP.NET server side code to call the WCF as intended.

MY QUESTION IS, how do I invoke the WCF method from clientside
Javascript/AJAX?

This is how I'm doing it now but not much success. The follow
javascript function calls the service hosted in IIS with endpoint
"JSON".  WCF function "GetxxxxxByLogon" has one parameter - strLogon
and returns a

function Findxxxxx() {
                var url = 'http://localhost/xxxxxServiceWeb/xxxxxService.svc/
JSON/GetxxxxxByLogon';
                var oUserNameTxt = document.getElementById
('ctrlLogin_UserName');
                var oParam = 'strLogon=' + oUserNameTxt.value;

                var myAjax = new Ajax.Request(
                                                                                
url,
                                                                                
        {
                                                                                
                method: 'post',
                                                                                
                contentType: 'application/json',
                                                                                
                parameters: oParam,
                                                                                
                onComplete: showResponse,
                                                                                
                onFailure: function() {
                                                                                
                        alert("FindXXXXX call failed.");
                                                                                
                }
                                                                                
        }
                                                                                
);
        }

"onFailure" handler keep firing and I'm not sure what to do next...

This is the signature of the WCF operation:

public IList<Group> GetXXXXXByLogon(string strLogon)
{
    ...
}

Advice? New to this not sure how to structure the Ajax.Request...
especially format of "oParam" above (I'm guessing it resembles query
string, is that correct?)

Client side error messsage (from "onFailure" handler) is:

{"ExceptionDetail":
{"HelpLink":null,"InnerException":null,"Message":"Encountered
unexpected character 's'.","StackTrace":" at
System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader
reader, XmlException exception)\u000d\u000a at
System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()\u000d
\u000a at
System.Runtime.Serialization.Json.XmlJsonReader.ReadNonExistentElementName
(StringHandleConstStringType elementName)\u000d\u000a at
System.Runtime.Serialization.Json.XmlJsonReader.Read()\u000d\u000a at
System.Xml.XmlBaseReader.IsStartElement()\u000d\u000a at
System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName,
XmlDictionaryString namespaceUri)\u000d\u000a at
System.ServiceModel.Dispatcher.DataContractJsonSerializerOperationFormatter.IsStartElement
(XmlDictionaryReader ...
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4
(MessageRpc& rpc)\u000d\u000a at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3
(MessageRpc& rpc)\u000d\u000a at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2
(MessageRpc& rpc)\u000d\u000a at
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1
(MessageRpc& rpc)\u000d\u000a at
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean
isOperationContextSet)"}


Looks pretty jibberish to me and "Encountered unexpected character
's'." is most suspicious (But strLogin = root, I'm not sending
anything with an "S"...)

Any suggestion? Thank you.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to