Wednesday, September 20, 2006

Disabling the ability to 'Set Web Reference' to a Web Service

You may wish to expose a 'private' web service such that in order for a new client to access it, the client must be furnished with a pre-built proxy class.

It seems there are two ways to accomplish this:

1. Implement the equivalent of the following in the WEB.CONFIG:


<webservices>
<wsdhelpgenerator href="DefaultWSDLHelpGenerator.aspx">
<!-- disable the web service test page -->
<wsdlhelpgenerator href="">
</wsdlhelpgenerator>
</webservices>


2. Implement the equivalent of the following in the WEB.CONFIG:


<webservices>
<protocols>
<remove name="Documentation">
</remove>
</protocols>
</webservices>


After implementing option #1, two things are very different:

1. Instead of help, you get a blank page in your browser.

Pointing your browser at the web service no longer yields the web service's Home /Help page. You know, the one with the big deep blue title banner with a 'invokable' (hyper-linked) list of all of the web methods below a line of text that reads "The following operations are supported. For a formal definition, please review the Service Description."



2. You cannot set a Web Reference to the service.

Trying to set a Web Reference to the Web Service from Visual Studio will ultimately result in an error. VS will be able to find and list the Web Service and it looks promising but selecting it and saying 'go' is an exercise in futility.

After implementing option #2, things are the same as implementing option #1 except that instead of getting a blank web page you get an error page saying:

Request format is unrecognized.


Presumably this is because a request for the main asmx page is interpereted as a documentation request and that protocol has been removed from the http handlers vocabulary. ... or something like that.

C# Sucks!

JK!! Seriously, though, somewhere around C#-3 we should have inculcated ourselves with the question: "Does 'CAN' == 'SHOULD...