views:

476

answers:

1

Hello,

I have a graph component in Flex and my end-user wants to be able to manipulate this control in Flex, and then export the result into Powerpoint. I don't have a problem exporting an Image to Powerpoint, but where I am running into a problem is with exporting the Flex component to a .NET web service. Here is the code I have come up with...

The Web Service Declaration:

<mx:WebService id="ws" wsdl="http://localhost:59228/CreateImageService.asmx?wsdl"&gt;
<mx:operation name="CreateImage" resultFormat="xml"/>
</mx:WebService>

The Flex code:

    private function btnCreateImage():void {
    var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(TeamChart);
    var imageByteArray:ByteArray = imageSnap.data as ByteArray;

    ws.CreateImage(imageByteArray);

    //swfLoader.load(imageByteArray);

}

And the Web Service code:

    [WebMethod]
    public void CreateImage(byte byteArrayin)
    {
        CreateImage createImage = new CreateImage();
        createImage.byteArrayToImage(byteArrayin);
    }

I know the component is being converted successfully to a ByteArray because I can use SWFLoader() to make it reappear within the Flash canvas. If I try to send the bytearray to the .NET web servie, I get a SOAP errr. If I submit a 0 to the web service, this will at least hit the web service.

I'm not quite sure where the problem is, but I fear it's something simple that I'm overlooking.

Much appreciated,

-Matt

+2  A: 

I figured it out. I had to encode the image as a base64 string and send it to .NET that way. Here is my code:

Flex:

private function btnCreateImage():void {
    var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(TeamChart);
    var image64BitText:String = ImageSnapshot.encodeImageAsBase64(imageSnap);

    ws.CreateImage(image64BitText);

    //swfLoader.load(imageByteArray);

}

.NET Web Service

public Image byteArrayToImage(string base64ImageString)
{
    // Convert Base64 String to byte[]
    byte[] imageBytes = Convert.FromBase64String(base64ImageString);
    MemoryStream ms = new MemoryStream(imageBytes, 0,
      imageBytes.Length);

    // Convert byte[] to Image
    ms.Write(imageBytes, 0, imageBytes.Length);
    Image image = Image.FromStream(ms, true);
    return image;
}

Hope this helps someone else,

-Matt

mattdell
pefect! thanks!
Sander Versluys