We have a ASP.NET application running and i have added a WCF Rest service to it. Locally and when deployed on test environments this works fine. The issue is when we deploy to our production environment, which is only HTTPS.
I have searched and read most of the answers online and have tried so many things. All with no luck.
Here is our simple code
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ReportingService
{
public ReportingService()
{
Thread.CurrentPrincipal = HttpContext.Current.User;
}
[OperationContract]
[WebGet(UriTemplate = "get/{id}", ResponseFormat = WebMessageFormat.Json)]
[PrincipalPermission(SecurityAction.Demand)]
public List<RawReportTable> GetReport(string id)
{
...
}
}
In Global.asax.cs we have
RouteTable.Routes.Add(new ServiceRoute("api/reporting", new WebServiceHostFactory(), typeof(ReportingService)));
In our web.config we have the following defined for system.serviceModel
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="api" helpEnabled="true" automaticFormatSelectionEnabled="true" maxBufferSize="500000" maxReceivedMessageSize="500000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport" />
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<endpointBehaviors>
<behavior name="api">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="d5 85 5b 37 89 47 6f 89 71 5b b7 5d 87 6f 2e e5 24 aa 57 b6" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ReportingService">
<endpoint address="api/reporting" behaviorConfiguration="api" binding="webHttpBinding" bindingConfiguration="webBinding" contract="WayfinderFM.Service.api.ReportingService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
With this set up I get the following errors: Request Error: The server encountered an error processing the request. See server logs for more details.
I thought (and some example show) that I no longer need the services/endpoint stuff in the configuration as it is registered in the routing.
Removing that part we still get the same error. I have tried lots of different configurations, all with no luck.
The weird thing is /api/reporting/help actually shows. Just can't use any of the services.
Anybody have any idea? I'm hoping it is something simple I have missed.
Thanks all
Edit
I believe it is to do with the [PrincipalPermission(SecurityAction.Demand)] We use this to make sure the user is authenticated and we can access the token. I've found PrincipalPermission.Demand() failing once WCF Service was moved to SSL which sadly doesn't have an answer to it.
Hate to answer my own question, but after reading Rajesh's message I looked into the error more. As my edit says it was related to the PrincipalPermission attribute. If I removed that it was running my code and failing in my authentication.
So back to searching the internet and I found http://forums.silverlight.net/t/34954.aspx/1
I just added to the serviceBehaviours. So it looks like
<serviceBehaviors>
<behavior name="">
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="None"/>
</behavior>
</serviceBehaviors>
Now it works, I can call my services and get rejected unless I am authenticated etc. Yay
Hopefully this helps someone else with this issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With