WCF:使用消息合同,使SOAP头 [英] WCF: Use a Message Contract to make a Soap Header

查看:236
本文介绍了WCF:使用消息合同,使SOAP头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个SOAP头添加到我的web服务。我打算用这个来验证我的客户端(Windows移动设备)

I need to add a soap header to my web service. I plan to use this to validate my clients (Windows Mobile Devices).

我发现此链接: http://www.c-sharpcorner.com/UploadFile/rog_21/soapheaders05172007120046PM/soapheaders.aspx

这正是我想做的事情。但它不是对WCF写入。

Which is exactly what I want to do. But it is not written for WCF.

我已经做了一些研究,我似乎由的若干 = http://msdn.microsoft.com/en-us/library/ms730255.aspx相对=nofollow>选项

I have done some research and I seem to be paralyzed by the number of options.

我基本上要一个简单的头添加到我的SOAP对象,这将是一个用户名和密码。客户端不使用WCF,所以SOAP头需要只是一个普通的肥皂头。

I basically want to add a simple header to my soap object that will be a user name and password. The client does not use WCF, so the soap header needs to just be a normal soap header.

在朝着正确的方向任何示例代码或猛推,将不胜感激。

Any Sample code or shoves in the right direction would be appreciated.

推荐答案

而不是定义一个DataContract,使用MessageContract

Rather than define a DataContract, use MessageContract

[MessageContract]
public class YourMessageType
{
  // This is in the SOAP Header
  [MessageHeader] public string UserName {get;set;}
  [MessageHeader] public string Password {get;set;}

  // This is in the SOAP body
  [MessageBodyMember] public string OtherData {get;set;}
  ...
}

这篇关于WCF:使用消息合同,使SOAP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆