Morteza
Morteza

Reputation: 174

WCF in "service reference" client gives less information in exception message than "web reference" client

I should call a web service in my C# application. When I add a service reference in Visual Studio to consume the service, in an exception situation I get this message:

An HTTP Content-Type header is required for SOAP messaging and none was found.

But, when I add a web reference the message is more rich and easy to understand the problem. The final part of this message is a business error message generated by the service. I was provided an invalid authentication token parameter for that service so this error message is returned:

Client found response content type of '', but expected 'text/xml'.

The request failed with the error message:

--

WEB SERVICE ERROR : UNAUTHENTICATED_ACCESS

I was preferred to use "service reference" approach but now I am in doubt. Is there a way to improve this kind of exceptions or to log raw response using "service reference"?

Upvotes: 0

Views: 426

Answers (1)

tom redfern
tom redfern

Reputation: 31760

I think the first message is much clearer.

It's telling you exactly what the problem is, which is the HTTP Content-Type header is missing from the service response. While this header is not mandatory, the HTTP specs say you should use it (from here):

Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body.

Microsoft obviously built into their proxy generation tooling the assumption that this header will always be present.

And no, you should not use WebReference. It's from .net 1.1

Upvotes: 1

Related Questions