SOAP Headers

Hi,

In classic web services I could define services like this:

[WebMethod]
[SoapHeader("SessionHeader", Direction = SoapHeaderDirection
.Out)]
public bool Logon(string user, string password)

To achieve the same thing (including the SOAP header) with WCF, it would appear that I have to do this:

[OperationContract]
LogonResponse Logon(LogonRequest request);

As such I have to define LogonResponse and LogonRequest myself, which is easy but a little tedious. It also imposes on the way the service is used at the client. Similarly, I used to be able to do this:

[WebMethod]
[SoapHeader("SessionHeader", Direction = SoapHeaderDirection
.In)]
public byte[] Synchronize(byte[] data, ref DateTime timestamp)

But now have to resort to:

[OperationContract]
SynchronizeResponse Synchronize(SynchronizeRequest request);

Is there any way I can make things easier for myself Can I attach a SOAP header / use MTOM etcetera without needing to define separate Request / Response classes

Thanks,
Kent



Answer this question

SOAP Headers

  • averageJ

    Thanks for the replies guys. Sorry I took a while to get back to you but I've been away from work for a while (but not long enough).

    OK, so yes I've seen and tried the MessageContract approach. Indeed it works, but it requires the definition of the extra request / response classes. And it therefore complicates the client code because it has to construct and populate the request object instead of just calling the service method.

    I have asked Scott for his samples so hopefully they will help me out. Other than that, I've just ordered a book on WCF because the MSDN "doco" is driving me crazy.

    Thanks,
    Kent


  • cVic

  • kc1

    You can use the MessageContract as described or you can add the headers manually. I've got sample on that if you want it.

    smason@microsoft.com

    Thanks!

    Scott



  • pflangan

    Sent.. ;>

    Thanks!

    Scott



  • AllanHO

    Hi Kent,

    Have you looked at the MessageContract attribute It give you greater control and flexibility in defining your headers and body in the soap packet.

    FYI: For your first scenario, you could define a security binding that automatically puts the usernametoken into the header and sends it over via transport or message security.

    HTH.



  • SOAP Headers