WCF cross-domain policy security error - c#

I am using VSTS 2008 + C# + WCF + .Net 3.5 + Silverlight 3.0. I host Silverlight control in an html page and debug it from VSTS 2008 (press F5, then run in VSTS 2008 built-in ASP.Net development web server), then call another WCF service (hosted in another machine running IIS 7.0 + Vista). The WCF service is very simple, just return a constant string to client.
When invoking the WCF service from Silverlight, I got the following error message,
An error occurred while trying to make a request to URI 'https://LabTest/Test.svc'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.
Here is the clientaccesspolicy.xml file, anything wrong?
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*">
</domain>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"></resource>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

This may be a shoot in the dark. But I recall running into a similar scenario setting up a WCF service locally on vista and IIS7. as it turned out i had to add some lines into my web.config file more specifically with the baseAddressPrefixFilters, Read this other post : Here . I had a problem because my default website had more than one host binding. it would take *:80 and www.mydomain.com:80 and WCF would not like that.

I had a similar problem but my solution was a lot simpler.
In my clientConfig file, my end point addresses for my different services had different URL's.
Some had local host and some had my machine's name in the URL.
Once I made all of them use local host it fixed my problem.

one idea could be to use fiddler and find the request which is requesting crossdomainpolicy xml. Is that failing? Check the address it is pointing to. I debugged my issue using that. It was pointing to root of the server and my crossdomainpolicy xml was in WCF project folder.

Related

Getting .Config custom section error only over network share

We have a client Windows application calling C# Web Services. Everything is in .Net Framework 4.0.
So basically, we deploy Web Services in IIS, and also the client application will be located on the server. The application will be executed on client PCs via a network share.
Everything works fine, every functionality works ok (Web Services, Windows functionalities, etc).
But we have an error reporting functionality that reads customs definition in the .Config file. The section looks like this:
<configuration>
<configSections>
<section name="exceptionManagement" type="Some.Namespace.ExceptionManagerSectionHandler,Some.Assembly"/>
<section name="ProductInformation" type="Some.Namespace.ProductInfoManagerHandler,Some.Assembly"></section>
</configSections>
The section will be read only when the application encounters an exception.
When executing the application locally on the server, the error reporting will work fine, but when executing the same assemblies from a network share (even on the same machine with a shortcut using the FQN of the machine and share), I will get this exception (line 5 is my "ProductInformation" custom definition):
Exception has been thrown by the target of an invocation. An error
occurred creating the configuration section handler for
ProductInformation: Request failed.
(\\Server\PATH\Some.exe.config line
5) Request failed.
But as I told before, every other functionalitiy will work just fine. And, of course, I got this at the end of my config :
loadFromRemoteSources enabled="true"
I really don't get it, since basically the code is fine when ran locally, but fails when ran from network share, but all other functionalities will work fine over network.
Any ideas?

launching a web service (.asmx) in a IIS 6.0

I have developed a web service with the .asmx extension using C# and i want to deploy this into my VPS which has Windows Server 2003 with IIS 6.
Service is running with Framework 4.0 and it's installed in the VPS also. When I upload the precompiled version into the VPS it shows a runtime error
Server Error in '/' Application.
Runtime Error
Description: An application error
occurred on the server. The current
custom error settings for this
application prevent the details of the
application error from being viewed
remotely (for security reasons). It
could, however, be viewed by browsers
running on the local server machine.
Details: To enable the details of this
specific error message to be viewable
on remote machines, please create a
<customErrors> tag within a
"web.config" configuration file
located in the root directory of the
current web application. This
tag should then have
its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are
seeing can be replaced by a custom
error page by modifying the
"defaultRedirect" attribute of the
application's <customErrors>
configuration tag to point to a custom
error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
can anyone help me on this?
Update
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to >service this request. Please review the specific error details below and modify your >configuration file appropriately.
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names >are case-sensitive.
Source Error:
Line 26:
Line 27:
Line 28:
Line 29:
Line 30: Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Source File: C:\Inetpub\vhosts\akashvahini.com\httpdocs\web.config
Line: 28
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET >Version:2.0.50727.3053
this is the new error message after enabling debugging in the web.config
You should enable debugging to diagnose the problem.
Microsoft has a very detailed explanation on how to enable detailed debugging over here.
Server Error in '/' Application.
That error is too generic, check the output after you enabled debugging and post the results.
And don't forget to disable debugging after your site goes live.
Update:
Seems to be permission related:
http://forums.iis.net/p/1042369/1454379.aspx
The ASPNET user account needs permissions for the folder that contains your asmx service.
Update2:
You can give the ASPNET user permissions using the file system permission dialog:
http://www.asp.net/learn/whitepapers/denied-access-to-iis-directories
Might look different on newer versions of Windows.
From my experience "Server Application Unavailable" means that you have got web sites that use different versions of .net in the same application pool.
the site that hosts your webservice needs to be in an app pool that only has .net 4.0 web sites. The application pool is configured on the Home Directory tab in the web site properties.
Looks to me like the application pool is trying to run two difference versions on .net.
Make a new application pool and call it something like .Net4 and then move the new site across to use this app pool and everything should work.
This error is shown by
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET >Version:2.0.50727.3053
Where the site with a .asmx should say .Microsoft .NET Framework Version:4.0 etc...

Problems posting via HTTPS from an IIS process (WCF & WF)

I have some code that wraps the PayflowPro .NET API. It essentially posts to a HTTPS address (a payment gateway) from C#. I can run this code locally and it works nicely. I can run it in my MSUnit tests and it works, and I can run it from a console application on my test environment and it also works.
I have a workflow hosted in IIS 6.1, which instantiates a class which in turn calls this code. When this workflow is started the code fails everytime; I get an error like System.Exception: Failed to connect to host Input Server Uri = https://pilot-payflowpro.paypal.com/ from the API object.
This exception is coming from the API, but I am completely lost as to how I can succesfully post from a console application but not from an IIS process.
The class is exactly the same, word for word.
I log in as administrator, so the console app is running as administrator. Therefore I have tried using the administrator account for the application pool for the website (for this testing only, obviously)
The console app can post so therefore the firewall / proxy aren't interfering... right?
Is there anything I need to adjust in IIS to allow an application to communicate outside? Are there any obvious security settings that I'm overlooking? Any suggestions for test cases to run to find out what might be going on?
edit: Turns out that this problem is somehow related to the VM environment in which the server is running. This problem doesn't occur on my development box, the test server or the production server - it's only occurring on the integration server. The cause is still unknown but I am no longer working on it.
This might be caused by an ASP.NET trust configuration issue. To check the trust level open the following file in an editor:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config (if ASP.NET 2.0)
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\CONFIG\web.config (if ASP.NET 4.0)
You may also need to edit the C:\WINDOWS\Microsoft.NET\Framework64 versions of these if you're running on 64 bit Windows.
Scroll down to the <securityPolicy> configuration section which looks like:
<location allowOverride="false">
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
<trustLevel name="High" policyFile="web_hightrust.config"/>
<trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
<trustLevel name="Low" policyFile="web_lowtrust.config"/>
<trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
</securityPolicy>
<trust level="Medium" originUrl=""/>
</system.web>
</location>
If you see anything other than <trust level="Full" originUrl=""/> it means the server is running under Partial Trust.
Open the .config file specified by the relevant policyFile attribute, for example web_mediumtrust.config if level="Medium".
It's highly unlikely that the server will be running under anything less than Low Trust.
Locate the <NamedPermissionSets> section, under this there is a <PermissionSet> that looks like:
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
This contains a number of <IPermission> nodes. Look for one that called WebPermission, it looks like this:
<IPermission
class="WebPermission"
version="1">
If it's missing or looks like:
<IPermission
class="WebPermission"
version="1">
<ConnectAccess>
<URI uri="$OriginHost$"/>
</ConnectAccess>
</IPermission>
You need to add or modify so it looks like:
<IPermission
class="WebPermission"
version="1"
Unrestricted="true"/>
This setting controls outbound and inbound access from your application to or from a URI.
It may also be necessary to ensure that the SocketPermission configuration is similarly configured:
<IPermission
class="SocketPermission"
version="1"
Unrestricted="true"/>
Turns out that this problem is somehow related to the VM environment in which the server is running. This problem doesn't occur on my development box, the test server or the production server - it's only occurring on the integration server. The cause is still unknown but I am no longer working on it.

Not able to load MicrosoftAjax.debug.js

I have an ASP.NET 3.5 web application which works perfectly fine on my local machine and when I deploy it on my Windows 2008 server. I am getting the following javascript error:
Message: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
Line: 4723
Char: 21
Code: 0
URI: http://localhost/ScriptResource.axd?d=e1Gld4LGHLsC4rWqevEI8zAMJKoVcCEVHBjdJIxcQLO9of6t7nNopbI1YyxJTv1QbaxN_lTSoz5Ly-VjBRHp08Mf3xxg5V9i5Z0AiXIkZRY1&t=6af1de90
I have a utility which can decrypt the URI and tell exactly what file is missing and it tunrns out that the file is ZSystem.Web.Extensions,3.5.0.0,,31bf3856ad364e35|MicrosoftAjax.debug.js|. Why am I not able to load this js file? Any help?
Possible options:
You've not installed .NET Framework SP1 on your server, so it can't find the 3.5 assemblies to generate the MsAjax file.
You've deployed your web.config file with <compilation debug="true"> while IIS has been configured to compile it in release mode.
I have run into a similar problem before when the development and production machines are set for two different time zones. When ASP.NET AJAX tries to load a script resource from an assembly, the last modified date/time of the assembly is validated. If the local time of the production server is "earlier" than the last modified date/time of the assembly, then an ArgumentOutOfRange exception is generated by ASP.NET AJAX when processing the request.
Really difficult to debug since the problem eventually resolves itself.
I suppose this might be possible with a System assembly if Copy-Local is set to true.
I was using some third party web services and the problem was with the following xml tag in the web.config:
<extendedProtectionPolicy policyEnforcement="Never" />
Once I removed this tag the error went away

What is a good proxy for me to install and test my Windows Service?

The deployment requirements for my app (a windows service written in C#) state the presence of a Proxy server.
From my interaction with the person who will install my app:
1. His company blocks access to internet via the proxy
2. He needs to provide the path to the proxy script in his IE Config.
3. He also needs to input a user-name/password.
My application needs to access a publicly hosted WebService. In preparation, I sent him a test Winform app. In the app.config file I used the setting mentioned in this post .NET client app: how to reach Web Services in case of proxy?
However, it did not work. I customized the proxy setting in App.config as per his IE settings, yet nothing seemed to work.
I don't want to hard-code the proxy settings in my app using the System.Net classes. There is no doubt in my mind that I want to use the config file.
So, I want to install a proxy on a VPC image and try and get my application to run.
My question:
1. What is a good proxy that I can install on my VM (windows only - no linux/squid pls.) that will replicate the behaviour that I mentioned in 2 & 3 above.
2. In case it is of interest, the proxy settings I used was:
<system.net>
<defaultProxy >
<proxy usesystemdefault= “False“ proxyaddress=“http://10.1.10.10:8080“ bypassonlocal=“True“ />
</defaultProxy>
</system.net>
Assuming that the system will read the settings from IE, I also tried
<proxy autoDetect="true" />
It did not work.
Pls. let me know if my requirements are unclear.
The open source squid proxy has Windows binaries.
If you have a Windows Server OS in you VPC, you could try out Microsoft's very own ISA Server. There's a 180-day trial version here.

Categories

Resources