gpt4 book ai didi

wcf - 发送到 WCF 服务时在 Soap 信封中使用 json 正文

转载 作者:行者123 更新时间:2023-12-02 04:13:54 26 4
gpt4 key购买 nike

我需要与带有json主体的autentication的soap头接口(interface)。

我创建了这样的契约(Contract):

[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 header 添加到json请求中?
还有其他选项如何将 header 传输到服务?

谢谢, 迈克尔

最佳答案

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

从理论上讲,如果您实现自己的消息编码器,您将能够在 SOAP 正文中发送 JSON 内容并添加 SOAP header ,但是这种开发的复杂性并不值得。

您必须提供其他方式来验证您的客户。请改用自定义 HTTP header 。

关于wcf - 发送到 WCF 服务时在 Soap 信封中使用 json 正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3760055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com