Monday, March 26, 2012

call web services using bridging (ajax beta 2)

I have several web service methods(implemented in .net 1.1) to call, in a different domain. The response I get when callin any methods from this web service is the page I see at the URL where .asmx is located. The .asbx is:

<bridge namespace="Support" className="OLOS" ><proxy type="Microsoft.Web.Preview.Services.BridgeRestProxy" serviceUrl="http://suppsite/SuppServices/OLOS.asmx" /><method name="getGeodisInfo" ><input><parameter name="OrderInformation" /><parameter name="BUID" /></input></method><method name="getExpeditorsInfo" ><input><parameter name="OrderInformation"/><parameter name="BUID" /></input></method></bridge>

And the .aspx file:

.............. <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="~/OLOS.asbx" /> </Services> </asp:ScriptManager>..............Support.OLOS.getGeodisInfo({ 'OrderInformation' : txtSearchText.value, 'BUID' : ' ' }, OnSucessgetGeodisInfo, OnError, "OLOS Search");.............. function OnSucessgetGeodisInfo(result) { if (result != null) { var resultText = result; document.getElementById('res1').innerHTML = resultText; } }
 
In the innerHTML of the DIV where I show results I get the content from the page located athttp://suppsite/SuppServices/OLOS.asmx
I do not see the actual call to the web method being done. Fiddler shows a call tohttp://suppsite/CareServiceCall/OLOS.asbx/js/getGeodisInfo but the response... does not contain what the method should return...
Any ideas?
Thanks

So I'm guessing your service url for the Asmx endpoint should behttp://suppsite/SuppServices/OLOS.asmx/<method>. What you'll need to do, is implement a TransformRequest in your Bridge codebehind, and as part of this, you need to set the ServiceUrl of the BridgeRequestl on the BridgeContext to the correct serviceUrl for your method. Since this is asmx, I imagine what you want to do is something like:

public override void TransformRequest() {
BridgeRequest.ServiceUrl = BridgeRequest.ServiceUrl + "/" + BridgeRequest.Method;
base.TransformRequest();
}

Hope that helps,
-Hao


Thanks for the response. Indeed that woulddefinitely help, at least a little bit later in the development phase.

What I am actually trying to do here is: I want to have all the methods for this web service(http://suppsite/SuppServices/OLOS.asmx/) defined in the same .asbx.

I know that changing serviceUrl tohttp://suppsite/SuppServices/OLOS.asmx/getGeodisInfo does the job, but then the rest of the methods defined in the .asbx are not callable. Using the url suffixed with the method name, works only if the web service has GET support, otherwise is not working for me. I also need to get this working when the web service works with POST only. I currently do not need transforms for method returns... at least not for all of them.

Is there a way to define in the same .asbx multiple methods and use them from javascript(except the way provided in the above sample)?


What I posted below dynamically changes the serviceUrl for each bridge request to be the correct one based on the method being called, which indeed it only works for GET, but if you want to support POST for asmx, you will need to build your own Proxy type for the bridge to make POST requests in the format ASMX expects, as the RestProxy only supports GET requests.

Hope that helps,
-Hao


Thanks Hao, everything is crystal clear now.

No comments:

Post a Comment