Getting a MethodAccessException(in event log of server) and HTTP Error 401 Unauthorized(at client side) in WCF Rest Service in IIS6.0 Win2K3 enviorn - wcf

I wrote a WCF REST based service that uses webHttpBinding and uses JSON to post data.This service works fine in all of our internal environments. But in one of our environment which is exact replica of Production. It is not working. If I inspect in Firebug, I see "HTTP Error 401 Unauthorized" and in server I See following in the event log.
System.MethodAccessException
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous
MethodAccessException: System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(System.Web.HttpApplication, Boolean) at System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context)
I haven't pasted the whole event log. But,afore are the key parts of it.
I am not able to figure out what is happening, we are using custom httpmodule for authentication.
Need urgent help on this
Thanks in advance

From MSDN, a MethodAccessException occurs when you try to call a private/protected method from somewhere that you aren't allowed. This is thrown during reflection, which is more than likely what WCF is doing under the covers.
My bet is that one of your service methods is marked as private or protected.
This would work in your local environment because it's under Full Trust. Your production environment is most likely running in Medium Trust. (Under Medium Trust, you aren't allowed to bypass the accessibility modifiers.)
-- Tatham

Related

Getting 401 when WCF OperationInvoker calls another WCF service

We have an attribute called LoggingImplementationBehavior that causes a WCF Logging service to get called before and after service calls it's attached to.
This works great both locally and on the shared development server. However, on the staging server a 401 error is returned when a call is made to the Logging service from the invoker. To ensure that the issue is not in the Logging service I commented all code out so that it does nothing, but I still get this error when the stub is called.
In IIS Manager, Anonymous Authentication is enabled (and nothing else) at both the server level and at the services website level. Digest Authentication is disabled at both levels, so what could be the cause of these 401 errors?
I've seen others have this problem with large data but the data being sent here is quite small.
Any tips on how to continue debugging this problem would be greatly appreciated as I'm currently at a dead end.
The exact text of the error is:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Digest qop="auth",algorithm=MD5-sess,nonce="+Upgraded+v171b25f8f2632897bff13b10710dac91aa1d64068a3cccf011b44f8580e932354dfd50d56778ba404d674864cf9d5216e589c616fb1a48583",charset=utf-8,realm="Digest"'.
The remote server returned an error: (401) Unauthorized.

How do I access a workflow service in silverlight?

I have one worflow service named GetDataWorkflowService.xamlx that I want to use in Silverlight.
When I add a service reference to my application, it gives a message 'This Operation is not supported for the relative URI.' It still adds the reference, however.
When I use the referece:
Servicelient proxy=new ServiceClient();
proxy.GetDataCompleted += (o, a) => Debug.WriteLine("Result is " + a.Result);
proxy.GetDataAsync(123);
I get the following error:
An error occurred while trying to make a request to URI 'http://localhost:1234/GetDataWorkflowService.xamlx'. 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.
I don't understand what's happening.
A few things:
What happens if you use the WCF Test Client to call GetData()? Do you get an error or does that work just fine. If you get an error here concentrate on the server parts.
What happens if you set a service reference from a console application and call your workflow service. Same error or does that work?
Is the workflow service hosted in the same web site as the Silverlight client? If not do you have the cross domain policy files setup correctly.
Assuming the WCF Test Client works. Open up fiddler and compare the request from your Silverlight client with that from the WCF Test Client. What is different?
Enable tracing on the server to see if there are any exceptions or warnings that might provide more insight to what is wrong.
Check your startup project to be sure you are starting a web project and not the Silverlight project. For more details see Troubleshooting Workflow Services / Silverlight on my blog

Why do I get a 403 error when calling a WCF Webservice?

I'm really posting this question so that others searching for the answer can find it.
Scenario:
WCF Service: Has worked fine at some point but currently is returning 403 errors. The web.config looks fine as far as I can tell. This machine has set the web.config to disable transport and message security and is using BasicHTTPBinding.
When I call it with my client generated from the Service Reference in Visual Studio, I get a 403 error. The error indicates there is some problem with the authentication, but as far as I can tell there is no such problem.
To solve this problem, I used Fiddler to get the actual error code - in this case, a 403.1. This indicated that the executable for the service couldn't be run.
The actual problem ended up being that the ASP.NET version was set to 1.1, not 2.0+. So setting that to 2.0 resolved the 403 permission error.
Http 403 error is "Forbidden". There is something that is blocking access.
In cases where it worked at one point and then stopped, it is often a windows update that has tightend up the security.
Where is your WCF service installed?
What are the ACL's on these files?
What is the security context of your service? (Which account will be used to access the files)
Does that user have access to the files?

Silverlight WCF calls work in IE but not in FF

I'm having a WCF service deployed on one of my servers, and my Silverlight app on the other server. The problem I'm having is running it in Firefox 3.5. Opening in IE 6/7 works great, but when I open it in Firefox it loads the app, but on calling WCF service i get this:
An error occurred while trying to make a request to URI 'http://10.1.1.20:87/MyService.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.
(The connection works over VPN so don't worry about the IP address)
I have encountered a similar problem and after a lot of research I found that adding the following line of code into the constructor of my UserControl solved the problem:
bool registerResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.BrowserHttp);
More information about the WebRequest member can be found here.

WCF Service Error

I have a WCF service deployed on a windows 2003 server. We are using a WPF application to consume this service. The trouble is if we deploy a new version of WCF service or leave the IIS and WPF application idle for sometime and then try to execute a functionality, we are get the following exception:
The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 119 bytes of the response were:'<HEAD><TITLE>500: Server Error [20-0004]</TITLE></HEAD>
<BODY>
<H1>500: Server Error [20-0004]<H1>
</BODY>
</HTML>
Thanks and Regards,
A 500 error usually means there was an unhandled exception in the service. Look in the Windows event logs to see what happened.
It looks like you are creating a proxy / connection to the server, then leaving it open and using this proxy when needed.
There are two problems with this:
The problem you are getting due to timeout in periods of inactivity.
That the connection is maintained when it is not used reduces scalability.
A better way to do it is to create the proxy connection when you require it, then close / dispose of it after it gas been used. Normally I use the using statement for this.
when you get below mentioned error
500: Server Error [20-0004]
This is siteminder Web Agent error, If your website is SSO protected, then it might have Siteminder ISAPI issue with initializing.
Check Event and SSO logs.
Origin Blog