Select to view content in your preferred language

WPF Application + Get HTTPS Mapserver

1725
8
02-11-2011 02:36 AM
JacobSaugmann
Deactivated User
Hi

i'm having trouble getting my mapserver when the application runs the server returns 401 Not authorized.?

Ive tried this:
 public MainWindow()
        {
            InitializeComponent();

            Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());

            ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer()
            {
                Url = "https://validurl/",
                ID = "grundkort"
            };

            layer.InitializationFailed += new EventHandler<EventArgs>(layer_InitializationFailed);
            AddLayerWithCredentials(layer);
        }

        private void AddLayerWithCredentials(ArcGISDynamicMapServiceLayer layer)
        {
            WebClient challengeRequest = new WebClient();
            challengeRequest.DownloadStringCompleted += (sender, args) =>
            {
                map.Layers.Add(layer);
            };

            challengeRequest.DownloadStringAsync(new Uri(layer.Url));
        }

        void layer_InitializationFailed(object sender, EventArgs e)
        {
            Layer layer = sender as Layer;
            string exceptionMessage = layer.InitializationFailure.Message;
            MessageBox.Show(exceptionMessage);
        }


The user logged in is a member of agsusers on my Server.

Any idea?
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
Is your service secured with Windows Authentication as described here (http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//0093000000q4...)? If so, you can set Credentials property on your layer with your NetworkCredentials.

You can verify that your user can be authenticated. If you change your Internet Explorer options to always prompt for username and password and then go the layer URL from your web browser. Login with that specific user credentials, see if that works.
0 Kudos
JacobSaugmann
Deactivated User
Hi Jennifer

Thanks, now i prompt the user for credentials and sets the Credentials on the layer.

The map Initializes with no exceptions but the map wont show up?

The Service is secured with Windows Authentication as described in the link you posted.

Any idea?
0 Kudos
JenniferNery
Esri Regular Contributor
You can subscribe to Initialized and InitializedFailed events, check to see if layer's InitializationFailure is null or if an error had occured. Here's a good blog post on how to troubleshoot a blank map: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2009/08/24/Troubleshooting-blank-layers.aspx
0 Kudos
JacobSaugmann
Deactivated User
Hi Thanks

Its only a problem from my WPF application
Here are an image showing the same mapserver service in a Silverlight and a wpf application
its only in the silverlight the map shows up?



I need to use the wpf for this project .. any idea on how to get the map to show in my application.. no exceptions are thrown and the layer Initializes?

When i work in Sillverlight i can't se the map when i debug only when i deploy the application to my local IIS and run the application as a Https:// site ..
0 Kudos
JenniferNery
Esri Regular Contributor
Please try to run Fiddler and inspect the web requests. http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2009/08/24/Troubleshooting-blank-layers.aspx.

I suspect that you just need to supply the NetworkCredentials for the layer that uses secured service. Something like this or maybe create a class that will get/set Credentials from a UserControl so that you don't hardcode your credentials.

xmlns:net="clr-namespace:System.Net;assembly=System">
<Window.Resources>
 <net:NetworkCredential x:Key="MyCredentials" UserName="myUserName" Password="myPassword" Domain="myDomain"/>
</Window.Resources>

<esri:Map x:Name="MyMap">
<esri:ArcGISTiledMapServiceLayer Url="mySecuredServiceURL" Credentials="{StaticResource MyCredentials}" InitializationFailed="Layer_InitializationFailed" Initialized="Layer_Initialized"/>
</esri:Map>
0 Kudos
JacobSaugmann
Deactivated User
Ok, this is strange, when Fiddler2 is running then the map loads just fine everything shows up i can zoom in and out, but the moment i close fiddler the map won't load anymore? - Still no exceptions
0 Kudos
JenniferNery
Esri Regular Contributor
Yup that is weird. I have never seen Fiddler interfere with my apps except when I worked with Windows Phone 7 Beta before. But you are using WPF and no issue with Fiddler comes to mind.
0 Kudos
JoeShmoe
Deactivated User
I'm not sure if this the same issue, but I've seen a similar issue with web-connections only working via Fiddler:

.NET has a maximum number of simultaneous connections to an internet domain.  Its seems that exceeding this threshold simply drops the outgoing request.  Running Fiddler (an HTTP proxy) breaks this behavior, "fixing" the problem.  You must use a lower-level port monitor (EG:  WireShark) to see the true behavior. 

In normal .NET apps, you'd fix this in your app.config:

<?xml version="1.0"?>
<configuration>
<system.net>
  <connectionManagement>
   <add address="*" maxconnection="65000" />
  </connectionManagement>
</system.net>
</configuration>
0 Kudos