1

我正在核心上创建一个 wcf 客户端。我创建了一个绑定。

var binding = new System.ServiceModel.BasicHttpsBinding();

我需要在 ws-addressing 请求中添加 MessageID、ReplyTo 字段。如何正确执行?

我试图覆盖请求 - 它没有用。所有的例子大多是在通常的网络框架上似乎有一个库 microsoft.web.services2,但我不明白如何使用它。

4

1 回答 1

1

我正在处理相同的要求,我发现修改标头的方法是使用OperationContextScope并使用OperationContext.Current.OutgoingMessageHeaders和更改属性。

public async Task<getAttorneyResponseStructure> GetAttorneyAsync(GetAttorneyRequestStructure getAttorneyRequestStructure)
{
  try
  {
    using (new OperationContextScope(Client.InnerChannel))
    {
      //Client Custom Header
      getAttorneyRequestStructure.AttorneyHeader = Header;
      
      //Change the properties to ReplyTo/MessageId
      OperationContext.Current.OutgoingMessageHeaders.To = new Uri("http://rydwvgsn01.spga.gov.sa/GSBExpress/Legal/MOJAttorneyInquiry/2.0/AttorneyInquiryService.svc");

      OperationContext.Current.OutgoingMessageHeaders.Action = "http://tempuri.org/IAttorneyInquiryService/GetAttorney";

      return await Client.GetAttorneyAsync(getAttorneyRequestStructure);
    }
  }
  catch (Exception e)
  {
   throw;
  }
}
于 2021-11-18T08:31:31.127 回答