Custom HTTP response header to identify server in a farm.

We wanted to follow recommendation from http://omaralzabir.com/best_practices_for_creating_websites_in_iis_6_0/ to

“add “From” header and set the server name. I do this on each webserver and specify different names on each box. It’s handy to see from which servers requests are being served. When you are trying to troubleshoot load balancing issues, it comes handy to see if a particular server is sending requests”

 

However one of the client of our rest service reported that From value in the response header is not valid and causing the .net HttpClient to throw an exception.

Innermost Message: The header cannot be added. Make sure to add request headers to HttpRequestMessage, response headers to HttpResponseMessage, and content headers to HttpContent objects.

Innermost Source: Microsoft.Net.Http

Innermost StackTrace: at System.Net.Http.Headers.HttpHeaders.CheckHeaderName(String name)

  at System.Net.Http.Headers.HttpHeaders.AddWithoutValidation(String name, String value)

  at System.Net.Http.HttpClientChannel.AddHeaderValues(WebHeaderCollection source, Int32 index, String header, HttpHeaders destination)

  at System.Net.Http.HttpClientChannel.CreateResponseMessage(HttpWebResponse webResponse, HttpRequestMessage request)

  at System.Net.Http.HttpClientChannel.GetResponseCallback(IAsyncResult ar)

HTTP/1.1 200 OK

Date: Fri, 09 Mar 2012 07:29:25 GMT

Server: Microsoft-IIS/6.0

From: FARMSRV04


According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

The From request-header field, if given, SHOULD contain an Internet e-mail address for the human user who controls the requesting user agent. The address SHOULD be machine-usable, as defined by “mailbox” in RFC 822 [9] as updated by RFC 1123 [8]:


 

      From   = “From” “:” mailbox

An example is:       From: webmaster@w3.org

This header field MAY be used for logging purposes and as a means for identifying the source of invalid or unwanted requests. It SHOULD NOT be used as an insecure form of access protection. The interpretation of this field is that the request is being performed on behalf of the person given, who accepts responsibility for the method performed. In particular, robot agents SHOULD include this header so that the person responsible for running the robot can be contacted if problems occur on the receiving end.

Actually standard doesn’t specify From as expected RESPONSE header(only as request).
however we should rename the custom header to something else to avoid conflicts, e.g.


FromServer: FARMSRV04

Make WCF services to help use the same namespace when called from WCF Clients

We have two services, that can be called independently, but also can be used together. They have some common types, and if they called together, default Visual Studio proxy generation will create the same types in different namespaces.
There are multiple articles, that recommend to use command line SvcUtil instead of Visual Studio IDE.
The article How to reuse types across service endpoints suggests on client side manually update Reference.svcmap to include multiple <MetadataSources> and NamespaceMappings
Alternatively svcutil does allow you to specify multiple endpoints at a single time and utilize /r(/reference)  and /n(/namespace) parameters
.Another commonly discussing solution is to  Share Types Between WCF Service and Client., but client not always has access to served data types.

If you are writing services and wish to simplify coding by your clients, consider to create additional “wrapper” service, that will include implementations of both interfaces, that are implemented by original services.
The approach is mentioned in  Generating Proxy class file for webservices with sharing TYPES and Meineck.Net: WCF: Hosting multiple WCF services as one single service.
Note that wrapper service will describe methods from both services, but the actual methods are trivial- just redirect to individual services implementation.

Use WCF Binary Encoding when Host in IIS6

I wanted to replace .Net Remoting calls with WCF.

Article From .NET Remoting to the Windows Communication Foundation (WCF)was very useful for me. It was misleading reference to Attribute ReturnUnknownExceptionsAsFaults which doesn’t exist any more.It has been changed to IncludeExceptionDetailInFaults,

I wanted to use WCF Binary Encoding when Host in Windows 2003 Server(IIS6) instead of text encoding, that is coming out-of-the-box
I found the blog WCF: Enable Binary Encoding Over Http
and literally copied custom binding settings from the blog
<binding name=”NetHttpBinding”>

         <reliableSession />

         <compositeDuplex />

         <oneWay />

         <binaryMessageEncoding />

         <httpTransport />

       </binding>

I was able to call the service successfully, but then client  was timed-out on response. It took me some time to debug until I recognized that the settings include    <oneWay />

Obviously it should be removed, if i am using a synchronous call.

So the minimum custom binding settings is
<binding name=”BinaryHttpBinding”>

          <binaryMessageEncoding />

         <httpTransport />

</binding>

If you have big objects to transfer, you need to increase size limits similar to the following
       <binding name=”BinaryHttpBinding”><!–For Remoting–>
                   <binaryMessageEncoding >
                       <readerQuotas   maxStringContentLength=”43647″ />                    </binaryMessageEncoding>
                   <httpTransport maxReceivedMessageSize=”83647″ />                 </binding>

Discussion that helped http://stackoverflow.com/questions/3367197/wcf-custombinding-duplex-fails-to-open-client-port

WCF: Suppress authentication for testing on different domain.

I have a WCF service and client, which worked fine, when I debug it on my local machine.

However when I deployed the service to test server on the different domain.


I’ve started to receive error

System.ServiceModel.Security.SecurityNegotiationException: The caller was not authenticated by the service. —> System.ServiceModel.FaultException: The request for security token could not be satisfied because authentication failed.

I’ve found a few similar recommendations, e.g.
<wsHttpBinding>
                <binding name=”CustomBinding”>
                    <security mode=”None”>
                        <message establishSecurityContext=”false”/>
                        <transport clientCredentialType=”None”/>
                    </security>
                </binding>
            </wsHttpBinding>
 
 
Unfortunately, it didn’t work for me.
Fortunately, after I’ve replaced wsHttpBinding  to basicHttpBinding , my client is able to access the server. 

OutOfMemoryException in Microsoft WSE 3.0 Diagnostics.TraceInputFilter

We are still using Microsoft WSE 3.0 and on test server started to get
 
Event Type:        Error

Event Source:    Microsoft WSE 3.0

WSE054: An error occurred during the operation of the TraceInputFilter: System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.

   at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)

   at System.Text.StringBuilder.GetThreadSafeString(IntPtr& tid)

   at System.Text.StringBuilder.set_Length(Int32 value)

   at System.Xml.BufferBuilder.Clear()

   at System.Xml.BufferBuilder.set_Length(Int32 value)

   at System.Xml.XmlTextReaderImpl.ParseText()

   at System.Xml.XmlTextReaderImpl.ParseElementContent()

   at System.Xml.XmlTextReaderImpl.Read()

   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)

   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)

   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)

   at System.Xml.XmlDocument.Load(XmlReader reader)

   at System.Xml.XmlDocument.Load(Stream inStream)

   at Microsoft.Web.Services3.Diagnostics.TraceInputFilter.OpenLoadExistingFile(String path)

   at Microsoft.Web.Services3.Diagnostics.TraceInputFilter.Load(String path)

   at Microsoft.Web.Services3.Diagnostics.TraceInputFilter.TraceMessage(String messageId, Collection`1 traceEntries).

 

After investigation it was found, that the problem related to trace files, that become too big. When they were deleted and new files were created, error gone.

 

Specify Expect100Continue=false in Web Service client.

The Web Service Provider that we are using recommends NOT send Expect100Continue header.
The specifying static value
System.Net.ServicePointManager.Expect100Continue=false;
is not good, because some other providers may prefer to use the header.
In the haacked’s “HttpWebRequest and the Expect: 100-continue Header Problem” post   comment of Mirronelli Jun 02, 2005 6:22 AM  suggest to specify webRequest.ServicePoint.Expect100Continue = false; for  each webRequest.

 If I am using web service(derived from SoapHttpClientProtocol) I can use ServicePointManager Class FindServicePoint method. 

Uri uri=new Uri(xws.Url);
ServicePoint servicePoint = ServicePointManager.FindServicePoint(uri);
// Debug.Assert(servicePoint.Expect100Continue == false, “Investigate why not?.”);
if (servicePoint.Expect100Continue == true)
{ //should happen only once for each URL
   servicePoint.Expect100Continue =
false;

}

Attempt to get Visio Class Diagrams from VS XSD files.

I wanted to have a diagram from .Net Dataset (stored as XSD) and include elements from XSD generated from WCF service.
I found that is not supported by MS tools. Dataset Designer doesn’t have any export facility.XSD files generated from WCF service, do not have any graphical interface at all.
I ended up with manually drawing in Visio objects used by WCF service and merge PrintScreens from VS Dataset Designer and Visio Class Diagram in Paint.Not a nice solution.
 I’ve posted a suggestion “Ability to export diagrams from XSD files.”. to MS.
 
Below are the links that I’ve read to find the solution.
From the thread “Import XSD to Visio?” :”The only way I know of is to write a little visio add-on using Visio SDK that reads the xsd and creates the corresponding Vision shapes”
Design and Generate Code with VisioVisio for Enterprise Architects
 
sparxsystems Enterprise Architect Modeling & Design Tools for your Enterprise -actually didn’t try.