2010-09-21 93 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標頭。