views:

13

answers:

1

Hello, I need to interface with a soap header of autentication with a json body.

I Created the contract like this:

[ServiceContract(Namespace = "http://tourico.com/webservices/hotelv3")]
public interface IHotelMobileFlow
{
    [OperationContract, WebInvoke(
       BodyStyle = WebMessageBodyStyle.Wrapped,
       RequestFormat = WebMessageFormat.Json,
       ResponseFormat = WebMessageFormat.Json)]
    SearchResultMobile SearchHotels(SearchRequestMobile request);

The service like this:

[AuthenticationRequired(typeof(HotelFlow), typeof(DefaultClientAuthenticationHandler))]
public class HotelMobileFlow : IHotelMobileFlow
{

for the attribute 'AuthenticationRequired' I need to send a soap header

<soapenv:Header>
      <aut:AuthenticationHeader>
         <aut:LoginName>host</aut:LoginName>
         <aut:Password>password</aut:Password>
         <aut:Culture>en_US</aut:Culture>
         <aut:Version>8</aut:Version>
      </aut:AuthenticationHeader>
   </soapenv:Header>

I created the request like this:

HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";

SearchRequestMobile sr = new SearchRequestMobile();

Is it possible to add the soap header to the json request? There is other option how to tranfer the header to the service?

Thanks, Michal

A: 

No it is not possible to add SOAP header to JSON request. Service will not be able to parse it. Your web request defines that you are sending JSON. It means that the content of the request can be only JSON.

Theoretically if you implement your own message encoder you will be able to send JSON content in SOAP body and add SOAP headers but the complexity of this development doesn't worth it.

You have to provide other way to authenticate your client. Use custom HTTP header instead.

Ladislav Mrnka