6 Replies Latest reply on Aug 28, 2007 1:21 PM by JoshBeall

    Building a custom Flex web services proxy server

    JoshBeall Level 1
      Hi All,

      I'm investigating the possibility of writing a custom proxy server for our web services, using ASP.NET. LiveCycle Data Services looks very cool and would do the proxying we need, but it's not in our budget this year, and I would still like to take advantage of proxying. I figured I could probably build something simple, and perhaps we may be able to move to LCDS at some point in the future.

      I did some searching and didn't find anything to help me get started. My next step would be to fire up Wireshark and start looking at traffic going back and forth to try and figure out what Flex expects from a web services proxy -- but I thought maybe some folks here would be able to point me to some documentation or other resources on writing a proxy?

      -Josh
        • 2. Building a custom Flex web services proxy server
          JoshBeall Level 1
          Thanks Mithai! However that's not really what I'm looking for. Here's the example PHP proxy they offer:

          <?php

          $dataURL = " http://www.macromedia.com/desdev/resources/macromedia_resources.xml";

          //note that this will not follow redirects
          readfile($dataURL);

          ?>

          Not quite what I wanted -- I need to be able to proxy both GET and POST requests, including SOAP requests.

          However, I could handle all that on my own just fine -- what I'm realizing I really need to know is, how do I configure my Flex client app to use a proxy for web service calls?

          -Josh
          • 3. Re: Building a custom Flex web services proxy server
            Peter Farland Level 3
            Hi Josh,

            Since all data services, including RPC services like <mx:WebService> are based on LCDS's messaging framework, you'd need to use a specific Channel implementation that hid the details of the messsaging framework from the ultimate SOAP endpoint.

            While that may sound complicated, it's actually not really. It's what the useProxy="false" setting does for you already! I would suggest that you continue to set useProxy="false" on your <mx:WebService> instance because you're not looking to use the LCDS ProxyService... but then invent a way to use the wsdl URL to contact your .NET proxy directly instead. Perhaps your .NET proxy can have a list of registered "destinations" that map to particular URLs, and that the wsdl url provided in the <mx:WebService> tag specify this in the url:

            <mx:WebService id="myWS" useProxy="false" wsdl=" http://myserver/myapp/proxy.aspx?destination=EmployeeService" ... />

            If you receive a GET request for this WSDL via the URL provided above, your proxy should notice the destination requested and make the request on your behalf.

            You could also modify the WSDL before returning it to update the <soap:address location="..."> before returning it to the client so that this location redirected back to your proxy with a suitable set of query parameters (or REST parameters, whatever style you want to take).

            One important thing to note is that due to limitations in the plugin architectures that some browsers expose to the player, your .NET proxy must convert any non-200 HTTP Response status codes into a 200. This is because in non-200 responses, the response body is not given to the player by the browser.

            Pete
            • 4. Re: Building a custom Flex web services proxy server
              JoshBeall Level 1
              Hi Pete,

              Let's say I was using LCDS (or some other proxy server that's compatible) -- how would I configure my Flex app to use that proxy? Obviously I need to tell Flex what the address of the proxy is, right? How do I do that?

              -Josh
              • 5. Re: Building a custom Flex web services proxy server
                Peter Farland Level 3
                I think you're confusing two things here - the way in which a client communicates with a service, and what that service ultimatly does for you. When you're using LCDS you're calling into a common, somewhat sophisitcated messaging framework that controls access to a range of services... one of which is the proxy service. This proxy service does ultimately act like an HTTP proxy on your client's behalf, but how it is contacted is complex because the messaging format is not designed just to do this one task.

                As such, I suggest you forget about useProxy="true" despite what the attribute happens to be named and what it ultimately does.

                It will be easier to just build your own little naming convention on a URL for proxying your requests to your own .NET based proxy. I suggested a mechanism for doing so in my previous post - just use the URL to point to a "distinguished" service that your proxy knows how to translate.
                • 6. Re: Building a custom Flex web services proxy server
                  JoshBeall Level 1
                  quote:

                  Originally posted by: pete
                  I think you're confusing two things here - the way in which a client communicates with a service, and what that service ultimately does for you. When you're using LCDS you're calling into a common, somewhat sophisitcated messaging framework that controls access to a range of services... one of which is the proxy service. This proxy service does ultimately act like an HTTP proxy on your client's behalf, but how it is contacted is complex because the messaging format is not designed just to do this one task.


                  I apologize for oversimplying; I realize LCDS does much more than proxying, but that's all I'm worried about at the moment, so that's why I keep mentioning it in the same breath as "proxy".

                  quote:

                  Originally posted by: pete
                  It will be easier to just build your own little naming convention on a URL for proxying your requests to your own .NET based proxy. I suggested a mechanism for doing so in my previous post - just use the URL to point to a "distinguished" service that your proxy knows how to translate.



                  It might be simpler, but my goal is to abstract away from the Flex app the fact that a proxy is even being used. I was under the impression that a proxy service would allow me to do this; however as I review the documentation I'm not entirely sure this is the case. It looks like I have to define explicit endpoints even if I am using a proxy?

                  What I had envisioned was that by setting up a proxy, all web service requests would be sent to the host I had specified as the proxy, regardless of what I had put for the web service WSDL and/or endpoint.

                  So here's my hypothetical situation (I'm making all this up -- it's what I'd like to do, not how things actually work):

                  {services-config.xml}
                  <service id="proxy-service" class="flex.messaging.services.HTTPProxyService"
                  messageTypes="flex.messaging.messages.HTTPMessage,flex.messaging.messages.SOAPMessage">
                  <properties>
                  <external-proxy>
                  <server>intranetProxy</server>
                  <port>80</port>
                  </external-proxy>
                  </properties>
                  </service>

                  Then I could define a bunch of web services in MXML:

                  <mx:WebService wsdl=" http://webservicesHost/myService.asmx?WSDL"/>
                  <mx:WebService wsdl=" http://webservicesHost/anotherService.asmx?WSDL"/>
                  <mx:WebService wsdl=" http://webservicesHost/handyService.asmx?WSDL"/>

                  Now, when it attempts to load the WSDL, it will relay the request through intranetProxy. When I actually call a web method, it relays the request through intranetProxy. No further needs to be done, and I don't need to touch the WSDL URLs or the WSDL documents.

                  If I go with the method of using the WSDL URL to contact my ASP.NET proxy directly, there are a few drawbacks:
                  -The proxy service is no longer abstracted away from the MXML/ActionScript code. If I ever need to move the proxy, I need to touch the code everywhere I use a web service.
                  -I have to rewrite the web service endpoints (defined in the WSDL) on the fly.

                  Neither of these are showstoppers. In fact, I'm already using this method -- but a proxy that is totally transparent to the Flex app seems like a better design goal. Is this possible, though? If I have to manually define every Web Service WSDL and/or endpoint that I want to proxy, then I'm no better off than using the WSDL URL to directly contact my ASP.NET proxy, and rewriting the endpoint defined in the WSDL as it passes through the proxy.