Monday, February 26, 2007

Unable to connect to endpoint: {wsdl path}

I was getting this obscure error while trying to insert data from Flex 1.5 into a database using a WebService and a stored procedure. Despite the error message, it likely has nothing to do with connection issues between Flex and your WSDL. More likely, it is due to a coding error. You may be trying to pass a complex object into a simple data type (either in your WSDL or in SQL). For me though, I don't think this was the case.

The problem for me ended up being that I was passing null data (the user, me, had left the input box blank), into a stored procedure that expected data. The weird thing was that if I put a space (or any other character) into that field and then deleted that space before submitting the form, it would go through fine. The error would only occur if I never entered (or deleted) anything in that field at all.

Anyways, I was able to fix it simply by putting a default value into my input variable in the stored procedure (in this case, a space):

@city varchar(100) = '  '

Thursday, February 22, 2007

Could not load WSDL: 500 java.net.SocketException: Connection reset

I'm in the process of building a Flex 1.5 app that calls two web services on another server. Frequently while testing the app, I would get hit with this error:

Could not load WSDL: 500 java.net.SocketException: Connection reset

It seemed to happen most often when first loading the app, although it occasionally happened while in the middle of using the app as well. I'm pretty sure it happened every time I made a change to the mxml code. Sometimes none of the data would load in the app when the error occurred and sometimes the data from one of the WSDLs would load (but not the other). To fix it, sometimes I could refresh the page or retry the action and it would work fine, but other times nothing I would do would fix it except for... clearing my browser cache, which would fix it every time. However, in a production environment, that wouldn't do.

The Internet was pretty quiet on the issue. One suggestion I found for related issues was to update the flex-config.xml file and set the <maxconnections> in the proxy section to 0 (unlimited - the default is 50). That didn't seem to help me though. However, I did find a way you can turn the WSDL proxy off, by adding useProxy="false" to the <mx:Webservice> tag. This did the trick for me. Make sure if you do this that you create a cross domain policy file on your WSDL server otherwise you won't be able to access them anymore. Adobe recommends that you use the proxy unless you have a good reason not to.

Writing a session variable or cookie from Flex

One limitation of Flex is that you're not able to create session variables or cookies using actionscript. Flex and Flash do have their own cookie substitute, Local Shared Objects, however LSOs can only be used within the Flex app that created them and they definitely can't be read by the browser itself.

But let's say you have a situation where you have a user login in your Flex app and you want that login to carry over to other pages on your site. The website already contains it's own login which creates a session variable or cookie to determine whether the user has been logged in. What you want to do is create that same variable when the user logs into your Flex app so that when they browse to other pages in your site they stay logged in.

This can be solved pretty easily using a hidden frame on the same page as your Flex app. Just add a simple iframe tag to your page:

<iframe name="loginHide" frameborder="0" width="700" scrolling="no" height="0"></iframe>

Then create a page that accepts login info in the query string and uses that info to create the session or cookie (the same as your login page). When the user logs in to your Flex app, send the login info to the page you created and target the hidden iframe:

getURL("loginHidden.aspx?userName="+userName+"&password="+password, "loginHide");

Voila! The variable is created. Of course, this is only one way to do it. If your Flex app exists in a popup window, you could just use javascript in your getURL function to refresh the popup's parent page, sending it the login info in the query string the same way. Or you could even send the login info to any page (target="_blank"), if you don't mind a new web browser window opening when the user logs into your flex app. The hidden frame gets around this problem though.