0

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"?

Morteza
  • 164
  • 1
  • 10
  • The second message is not clear, it tells you that the header was empty when in all likelihood it was probably missing and actually reports an authentication error which just muddies the water. – tom redfern Feb 14 '17 at 14:34

1 Answers1

1

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

Community
  • 1
  • 1
tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • Thank you @tom. I am agree with you partly, but I can't change the service and its response contains a helpful message : **WEB SERVICE ERROR : UNAUTHENTICATED_ACCESS** . – Morteza Feb 15 '17 at 06:02
  • @morteza this is not a helpful message. The problem is not authentication. The problem is that the service does not comply with w3 guidance. – tom redfern Feb 15 '17 at 06:55
  • I see. It sounds a misunderstanding here. 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. – Morteza Feb 15 '17 at 07:48
  • @Morteza you should add this information into your question as it's relevant – tom redfern Feb 15 '17 at 09:19