Rick Glos

I've been attempting to get a WPF XBAP app to call a web service and return a simple message all day and cannot.

System.Security.SecurityException was unhandled
Message: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

It's the same problem, referenced these posts:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1785511&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1436424&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1616816&SiteID=1

I've even attempted to use Orcas Beta2 and that did not work.

  • Solution
    • Library
    • WebService
    • ConsoleApp - works!
    • WindowsApp - works!
    • WPF App - works!
    • XBAP App - fails!

Could someone enlighten me Project Here

Am I missing some simple property that would allow and F5 debug

Thanks,

Rick



Re: Windows Presentation Foundation (WPF) XBAP Web Service Call

Yi-Lun Luo - MSFT

Hello, in a partial trust environment, you can only access web services located at the XBAP¡¯s site of origin. But when debugging, VS won¡¯t consider to have the same site of origin as the web service it references. You¡¯ll need to add -debugSecurityZoneURL <URL> to the command line arguments to avoid this issue. For more information, please refer to http://msdn2.microsoft.com/en-us/library/bb613597(VS.90).aspx.






Re: Windows Presentation Foundation (WPF) XBAP Web Service Call

Rick Glos

I actually tried adding -debugSecurityZoneURL prior to asking for help and it did not work. It still does not work. The link to my project in the first post had this set but apparantly this is kept in the *.user file, which I deleted prior to zipping it.

So here's my steps to try and get this to work:

  • From Solution Explorer, right-click and unload the XBAP project.
  • From Solution Explorer again, right-click and edit the xbap.csproj.
  • Edit the <StartArguments> node to look like this:
    • <StartArguments>-debug "$(MSBuildProjectDirectory)\bin\$(Configuration)\$(AssemblyName)$(ApplicationExtension)" -debugSecurityZoneURL "http://localhost:1106"</StartArguments>
  • Save the change
  • From Solution Explorer, right-click on the XBAP project and reload it.
  • From Solution Explorer, right-click on the ClientService.asmx in the WebService project and View in Browser to get it to start up on port 1106.
  • Finally, select the XBAP project from Solution Explorer and hit F5 to run it.

I still get the security error posted above. Does it work for you Are my steps incorrect

Thanks,

Rick





Re: Windows Presentation Foundation (WPF) XBAP Web Service Call

Chango V. - MSFT

Have you ruled out the specific cause for EnvironmentPermission SecurityException discussed on the second thread you are linking to It looks like you are using a test port number > 1024...






Re: Windows Presentation Foundation (WPF) XBAP Web Service Call

Rick Glos

You are correct as I was using 1106 > 1024 so I went through and changed it to 924 and still received the same error. Sad

Here's my steps below.

First I went into the WebService.csproj and changed the port from 1106 to 924:

<ProjectExtensions>

<VisualStudio>

<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">

<WebProjectProperties>

<UseIIS>False</UseIIS>

<AutoAssignPort>True</AutoAssignPort>

<DevelopmentServerPort>924</DevelopmentServerPort>

<DevelopmentServerVPath>/</DevelopmentServerVPath>

<IISUrl>

</IISUrl>

<NTLMAuthentication>False</NTLMAuthentication>

</WebProjectProperties>

</FlavorProperties>

</VisualStudio>

</ProjectExtensions>

I noticed that each project puts the port number all over the place (Ctrl+Shift+F on solution) - Settings.settings, Settings.Designer.cs, ClientService.disco, etc, etc.

I couldn't figure out how to update those ports #'s easily. I changed the value in the applications app.config but it still wanted to use the old 1106 port, so I removed and re-added the web service reference for each client project (Console, Windows, WPF, XBAP). That got rid of all references to 1106. I started up the WebService on port 924 and made sure that each client except the XBAP still functioned by F5, and they did.

Then I went into the XBAP.csproj and changed the StartArguments node to use port 924. I hit F5 and still got the same error.





Re: Windows Presentation Foundation (WPF) XBAP Web Service Call

Matt Galbraith

Hi Rick,

Just an idea... there's a chance your app got committed to the ClickOnce store at some point and debugging is just running the same app over and over. An easy way to test this is to change some small visual part of the app and debug again, making sure that the change was propagated. If not, you can find instructions on this forum for clearing your app store (mage.exe -cc from an SDK Command prompt being an easy one).

Hope this helps,

Matt






Re: Windows Presentation Foundation (WPF) XBAP Web Service Call

Matt Galbraith

Hi Rick,

I downloaded your repro app (from here: http://www.rickglos.com/files/XBAPCalltoWebService.zip) and looked at it. I was able to get the app running in partial trust from my local web server after the following minor tweaks to make the app not use a port > 1024.

1) Under "XBAP \ Web References \ Web Reference URL",

2) In the app.config file (under <applicationSettings>\<XBAP.Properties.Settings>)

Chango's previous posts on the subject are invaluable here since they are one of the best troubleshooting guides yet out about this scenario.

A couple other tips:

- If this doesnt help, try using a HTTP sniffer app like Fiddler to see what ports are being accessed for your .xbap / web service

- Always make sure the port used for the .xbap file matches the port being used to access the service. This is in addition to making sure the port is < 1024.

Hope this helps!

Matt Galbraith