Use json body in Soap envelope when sending to WCF service

I need to associate with the soap header to install using json body.

I created the contract as follows:

[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);

A 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 query as follows:

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 soap header to json request? Is there any other way to redirect the header to the service?

Thanks Michal

+3
source share
1 answer

No, you cannot add a SOAP header to a JSON request. The service will not be able to analyze it. Your web request determines that you are sending JSON. This means that the content of the request can only be JSON.

, , JSON SOAP SOAP, .

. HTTP-.

+1

Source: https://habr.com/ru/post/1765813/


All Articles