2010-09-21 95 views
3

我需要使用json主体与SOAP身份验证头接口。发送到WCF服务时使用soap信封中的json主体

我创建的合同是这样的:

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

这样的服务:为属性

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

'AuthenticationRequired' 我需要发送SOAP头

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

我创建了这样的请求:

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

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

SearchRequestMobile sr = new SearchRequestMobile(); 

是否可以将soap标头添加到json请求中? 还有其他选择如何将标题传输到服务?

谢谢Michal

回答

1

不,不可能将SOAP头添加到JSON请求。服务将无法解析它。您的网络请求定义您要发送JSON。这意味着请求的内容只能是JSON。

理论上,如果您实现自己的消息编码器,您将能够在SOAP主体中发送JSON内容并添加SOAP标头,但此开发的复杂性不值得。

您必须提供其他方式来验证您的客户端。改为使用自定义HTTP标头。