1

I am creating a wcf client on core. I create a binding.

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

I need to add MessageID, ReplyTo fields to the request for ws-addressing. How to do it correctly?

I tried to overwrite request - it didn't work. All examples are mostly on the usual net framework It seems there is a library microsoft.web.services2, but I do not understand how to use it.

sir
  • 51
  • 6
  • I'm not sure what you want to do is even possible. WCF support in core is limited, to say the least, and the ws-addressing basically means "callback support", which means SOAP server. WCF-core does not support SOAP servers. And never will: microsoft said that they consider SOAP a legacy. If you need SOAP with callbacks, net-core is not the technology you should use. – Morse Jun 01 '21 at 10:30
  • i solved my problem `CustomBinding binding = new CustomBinding(); binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, System.Text.Encoding.UTF8)); binding.Elements.Add(new HttpsTransportBindingElement());` – sir Jun 02 '21 at 06:11

1 Answers1

1

I'm working on the same requirement, I've found the way to modify the header is work with the OperationContextScope and work with OperationContext.Current.OutgoingMessageHeaders and change the properties.

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;
  }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Nasser X
  • 175
  • 3
  • 10