4

I am trying to hide my WCF as much as I possibly can. If some one enters the url to my WCF, they are displayed the response "Endpoint not found". If they try a get request, they are displayed with method not allowed because my service only accepts post requests.

I already have the following included in my web.config

    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp helpEnabled="false" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceDebug includeExceptionDetailInFaults="False" />
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

I would like to display no response unless they have the exact url and exact post parameters. I am not sure if I need to alter my "Custom error section". My understanding is custom errors is only for when an exception is thrown. Endpoint not found and method not allowed is not an exception.

Any help or suggestions would be greatly appreciated.

Alex Nolasco
  • 18,750
  • 9
  • 86
  • 81
Paul_D
  • 255
  • 2
  • 8
  • 21

2 Answers2

1

I would suggest implementing IServiceBehavior or IEnpointBehavior in conjunction with IDispatchMessageInspector or IDispatchOperationSelector. This way when the request is received you can write code to make a custom response.

I don't have an example that exactly fits your needs, but you can take a look at the article below where I modify XML namespace tags on an outgoing message. My thought is that if the request does not meet your criteria you could simply return null or 404. Also included are some MSDN articles on the topic.

How can I create custom XML namespace attributes when consuming a legacy SOAP service?

https://msdn.microsoft.com/en-us/library/system.servicemodel.description.iservicebehavior(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector(v=vs.100).aspx

https://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchoperationselector(v=vs.100).aspx

Community
  • 1
  • 1
John Meyer
  • 2,296
  • 1
  • 31
  • 39
1

Read this article https://blogs.msdn.microsoft.com/carlosfigueira/2011/05/09/wcf-extensibility-operation-selectors/

If you want to throw 404, you can throw it from OperationSelector as following:

...
throw new System.ServiceModel.Web.WebFaultException(System.Net.HttpStatusCode.NotFound);
...
Khoa Nguyen
  • 1,056
  • 2
  • 12
  • 20