Opened 16 years ago

Closed 16 years ago

#675 closed defect (fixed)

HttpServerConnection.RenderRuntimeMap() fails...

Reported by: MaksimS Owned by: ksgeograf
Priority: low Milestone:
Component: Maestro Version:
Severity: major Keywords:
Cc: External ID:

Description

While trying to get rendered map using:

Dim host As New Uri("http://server/mapguide2009/mapagent/mapagent.fcgi")
        Dim conn As New HttpServerConnection(host, "Administrator", "password", "en", True)
        
        Dim mapId As String = conn.GetResourceIdentifier("Folder/SubFolder/PLAN", ResourceTypes.MapDefinition, False)
        Dim mapDef As MapDefinition = conn.GetMapDefinition(mapId)
        Dim mapName As String = conn.GetResourceName(mapId, False)

        Dim rtMapId As String = "Session:" + conn.SessionID + "//" + mapName + ".Map"
        conn.CreateRuntimeMap(rtMapId, mapDef)
        Dim rtMap As RuntimeClasses.RuntimeMap = conn.GetRuntimeMap(rtMapId)

        Dim stream As System.IO.MemoryStream = conn.RenderRuntimeMap(rtMapId, 6259416.4634, 4320081.3816, 10000, 400, 400, 75)

Here, on conn.RenderRuntimeMap (last line) it throws following exception:

System.Net.WebException was unhandled by user code
  Message="The request was aborted: The request was canceled."
  Source="System"
  StackTrace:
       at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)   at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)    at System.Net.ConnectStream.Dispose(Boolean disposing)    at System.IO.Stream.Close()    at System.IO.Stream.Dispose()    at OSGeo.MapGuide.MaestroAPI.HttpServerConnection.RenderRuntimeMap(String resourceId, Double x, Double y, Double scale, Int32 width, Int32 height, Int32 dpi)    at Predmet.SetMapGuide() in D:\DEV\Legalizacija\Predmet.aspx.vb:line 285    at Predmet.Initialize() in D:\DEV\Legalizacija\Predmet.aspx.vb:line 147    at Predmet.Page_Load(Object sender, EventArgs e) in D:\DEV\Legalizacija\Predmet.aspx.vb:line 44    at System.Web.UI.Control.OnLoad(EventArgs e)    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.IO.IOException
       Message="Cannot close stream until all bytes are written."
       Source="System"
       StackTrace:
            at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
       InnerException: 

...instead of returning rendered Stream.

Change History (9)

comment:1 by ksgeograf, 16 years ago

Version: 2.0.1

This is very strange, because I use the WebClient.DownloadData call, so there is really nothing to change.

Are you certain that your parameters are correct?

If you use the source code for Maestro, what url does it send? (You can use fiddler to get the URL, if you dislike using the source code).

comment:2 by MaksimS, 16 years ago

Parameters are correct, I checked them multiple times.

Deploying Fiddler gave me some insight into what's happening beneath, but didn't pinpoint the source of an error. The only thing that's really strange is that it actually never reaches GETMAPIMAGE operation - described exception is being thrown following series of GETRESOURCEDATA and GETRESOURCECONTENT ops. As per inspector, the last valid GET is:

GET /mapguide2009/mapagent/mapagent.fcgi?OPERATION=GETRESOURCEDATA&VERSION=1.0.0&SESSION=c3d9fba6-ffff-ffff-8000-00215a501f4d_en_7F0000010AF20AF10AF0&FORMAT=text%2fxml&LOCALE=en&RESOURCEID=Session%3ac3d9fba6-ffff-ffff-8000-00215a501f4d_en_7F0000010AF20AF10AF0%2f%2fPLAN.Map&DATANAME=LayerGroupData HTTP/1.1
Host: proliant
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1)

After that follows a POST:

POST /mapguide2009/mapagent/mapagent.fcgi HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------8cad4b5fc35d432
Host: proliant
Content-Length: 1236
Expect: 100-continue
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1)

... and I see no POST parameters anywhere (?). That's the point where exception is being thrown.

One thing I noticed, though - while getting RuntimeMap object DESCRIBEFEATURESCHEMA operation is being issued (data requested) multiple times, although it returns just the very same named feature source schema. Named schemas should be internally cached in memory on Meastro API side, there's really no need to request for it's contents multiple times during a single session (i.e. DESCRIBEFEATURESCHEMA returns 104 KB of data in my case).

comment:3 by MaksimS, 16 years ago

As a sidenote - I'm using MGE 2009 / Windows 2003 / IIS / .NET

BTW, is there any AJAX viewer command actually utilizing GETMAPIMAGE operation? Plotting option maybe? I'm asking this so I could test it directly from viewer.

comment:4 by ksgeograf, 16 years ago

I think I've found the problem.

For some reason the Flush() call does not wait until the data is written. When the stream is disposed/closed, there are still data waiting. I think this is very machine specific, and I have never seen it myself.

I have re-arranged the code a bit to prevent this situation. If you check out the latest version of the code, it should be fixed.

I think that the "Print" command uses the GETMAPIMAGE.

What call for getting RuntimeMap issues all these DESCRIBEFEATURESCHEMA?

comment:5 by MaksimS, 16 years ago

One of probable causes for this is the fact that I'm running the code from development machine, while MG resides on remote server.

comment:6 by MaksimS, 16 years ago

Kenneth,

This specific line (see source above):

conn.CreateRuntimeMap(rtMapId, mapDef)

is responsible for issuing multiple DESCRIBEFEATURESCHEMA calls.

comment:7 by ksgeograf, 16 years ago

Status: newassigned

Yes, that might be why I have never seen the problem. I have tried on remote servers, but probably never called GetMapImage on such a connection.

The CreateRuntimeMap calls Describefeatureschema for each layer that is selectable. The runtime map must contain the primary key for the layer features to be selectable.

Do you have the same layer included many times in the map?

comment:8 by MaksimS, 16 years ago

No, I have no duplicate layers, but it requests DESCRIBEFEATURESCHEMA for each of them (over and over), although they're mostly coming from the same feature source. That's why I suggested Meastro API should utilize a small hashtable for keeping resulting feature sources content keyed by it's name, preventing failing over to MG every time during a single session.

comment:9 by ksgeograf, 16 years ago

Resolution: fixed
Status: assignedclosed

I have created issue #681 that explains the optimization you proposed.

Note: See TracTickets for help on using tickets.