Tuesday, October 31, 2006

Sending custom class object thru remoting using OpenAmf

Passing UDT from java to flex using openAmf based remoting.

Finally the battle is over. Was in lot of pain pasing a
custom object as response to remote call to java. 2 man days
wasted.

Java (server side) :

Remote Class (UDT): TestClass.java

package com.vishwajit.test.BO;

import java.io.Serializable;

public class TestClass implements Serializable {

private String testValue ;

public TestClass() {
}

public String getTestValue() {
return testValue;
}

public void setTestValue(String testValue) {
this.testValue = testValue;
}
}

Remote Method : (Inside Service.java)

public static TestClass Test()
{
TestClass obj = new TestClass();
obj.setTestValue("setyblch");
return obj;
}

Open AMF Mapping

(if you have not already set this one...)
<amf-serializer>

 <force-lower-case-keys>false</force-lower-case-keys>

</amf-serializer>

      


<custom-class-mapping>>

 <java-class>com.vishwajit.test.BO.TestClass</java-class>

 <custom-class>vishwajit.TestClass</custom-class>

</custom-class-mapping>



Client Side (flex / swf):

public function TestHandler (obj : Object ):void {

var testObj:TestClass = TestClass(obj);
Alert.show("" + testObj.testValue );
}

Wednesday, October 25, 2006

Problem invoking any webservice operation if the API contains a method called 'logout'

Figured out a weird issue with Flex 2.0 / Flash Player 9 . Your comments welcome.


Issue:
When you are calling any webservice where the API contains a method/function/operation named 'logout' your call wont be processed.
and you get the exception mentioned in trace .

Just to confirm the issue I tried writing webservice in Intersystems Cache and .NET 1.0 .
The issue lies with webmethod name 'logout' , if its renamed to something else the life is good.

Trace :
TypeError: Error #1034: Type Coercion failed: cannot convert MC{mx.rpc.soap.mxml::WebService@1393c41 mx.rpc::AbstractService/logout()}@132a7b9 to mx.rpc.soap.Operation.

Tuesday, October 17, 2006

Webservice Result for Flex 2

Getting result of Webservice.

Result is available in the operation object property lastResult.

Sample
Alert.show(loginWS.login.lastResult + "");

Crossdomin access for webservice

1 Invoking webservice in Flex without FDS
2 Solution for MessaginError message='Unknown destination'DefaultHTTP'.'

1
If You are not using FDS
On the Webserice Object
set 'proxy' = false
do not set the 'destination' property instead
set 'wsdl' to the path of wsdl

2 Use crossdomin.xml file on the server that is hosting the webservice. This file should grant access to clients domain. Place this file at the root of the webserver.

example

<?xml version="1.0"?>

<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>

   <allow-access-from domain="*" />

</cross-domain-policy>





Any other queries : Post comment.

Calling a webservice in Flex 2

Making a webservice call in Action Script 3.0
Without using FDS

Flex webservice Sample.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="creationCompleteHandler()" >

 <mx:WebService id="loginWS"

 

 wsdl="http://vishwajit/TestWS/Service1.asmx?WSDL"

  

 useProxy="false" 

 fault="wsFault(event)" >

 

 <mx:operation name="HelloWorld" result="HelloWorldResult(event)" 
>   


  </mx:operation>

 

 <mx:operation name="login" result="getLoginResult(event)"  >

    <mx:request xmlns="" >  

    <loginId>a1</loginId>

    <password>a1</password> 

   </mx:request>

  </mx:operation>

 </mx:WebService>

 

 

 <mx:Script>

  <![CDATA[

  import mx.controls.Alert;

  

  public function creationCompleteHandler()

  {

  

  

  loginWS.login.send();  

  //loginWS.HelloWorld.send();

 

  }

   

   

  public function HelloWorldResult(result : Object)

  {

   Alert.show("HelloWorldResult");

  }

   

   



  public function wsFault(fault:Object)

  {

   Alert.show(""+fault);

  }

   

  ]]>

 </mx:Script>

</mx:Application>




Time wasted/invested on the issue 2.5 Man days