3

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.

Community
  • 1
  • 1
lukem
  • 123
  • 1
  • 8
  • What is the error you get? Is it resource not found or Bad request or internal server error? Also do remove the service section as you are using the standardendpoint element. Also your certificate findValue has spaces. Can you try removing the spaces? Might be the certificate is not being found – Rajesh Jun 26 '12 at 16:29
  • So this morning I added (not sure why I didn't already have that!). Now the error shown is The server encountered an error processing the request. The exception message is 'Access is denied.' - I can't figure out why I wouldn't have access – lukem Jun 26 '12 at 23:29

1 Answers1

6

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

lukem
  • 123
  • 1
  • 8