发送到 WCF 服务时,在 Soap 信封中使用 json 正文
我需要与带有 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请求中? 还有其他选项如何将标头传输到服务?
谢谢,米哈尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,不可能将 SOAP 标头添加到 JSON 请求。服务将无法解析它。您的 Web 请求定义您正在发送 JSON。这意味着请求的内容只能是JSON。
理论上,如果您实现自己的消息编码器,您将能够在 SOAP 主体中发送 JSON 内容并添加 SOAP 标头,但这种开发的复杂性并不值得。
您必须提供其他方式来验证您的客户。请改用自定义 HTTP 标头。
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.