2

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">
<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

Matt Dell
  • 9,205
  • 11
  • 41
  • 58
  • Hi Matt, thanks for posting this.I have a similar doubt , I want to send a array of images from flex to a asp dot net web service .I also need to create a web method to pull the images from the server to the flex application . Can you please give a sample code of such a web service, I am pretty new to C#,ASP and Flex so struggling a bit.Here is the link to the question I posted on SO - http://stackoverflow.com/questions/5702239/how-to-pass-image-from-a-flex-application-to-a-asp-net-c-web-service . Thanks – deovrat singh Apr 18 '11 at 12:11

1 Answers1

2

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;
}
Matt Dell
  • 9,205
  • 11
  • 41
  • 58