c# - WCF:使用消息契约创建 Soap header

标签 c# visual-studio-2008 wcf

我需要向我的网络服务添加一个soap header 。我计划用它来验证我的客户端(Windows 移动设备)。

我找到了这个链接:http://www.c-sharpcorner.com/UploadFile/rog_21/soapheaders05172007120046PM/soapheaders.aspx

这正是我想做的。但它不是为 WCF 编写的。

我做了一些研究,我似乎对 number 感到瘫痪。 of options

我基本上想向我的 SOAP 对象添加一个简单的 header ,该 header 将是用户名和密码。客户端不使用WCF,因此soap header 只需是普通的soap header 即可。

任何示例代码或正确方向的插入将不胜感激。

最佳答案

不要定义 DataContract,而是使用 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;}
  ...
}

关于c# - WCF:使用消息契约创建 Soap header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2746995/

相关文章:

wcf - 为什么在第一次请求启用 ASP.Net 的 WCF 服务时 HttpContext.Current 为 null?

wcf - 在 WCF 测试客户端 (WcfTestClient.exe) 中按字母顺序列出服务操作

c# - 如何清空 EntityFramework DbContext?

c# - 我的 C# 程序被检测为病毒?

c# - 在 C# VS2008 项目中使用 sqlite 的数据访问方法?

wcf - ServiceSecurityContext.WindowsIdentity 的用途?

c# - 如何提高从数据库中获取大量数据的 Select 查询的性能

c# - 在Unity中有没有快速调试手机振动的方法?

c++ - 在 VS2010 中为平台工具集 v90 构建 C++ CLR 应用需要 Visual Studio 2008

c# - Visual Studio/Microsoft sql 关系键错误