locked
Custom SOAP Header without WSDL definitions?

    Question

  • I am building a web client in VS 2005 using VB.Net. The client must pass username and password in the SOAP header, but these required parameters are not explicitly defined in the web service's WSDL. I have been unable to find a way of accomplishing this. The sample code I find regarding custom SOAP Headers all seem to assume the WSDL contains the requirements and VS 2005 doesn't seem to allow compilation of the web client unless the Spah header elements are somewhere referenced.

    Does anyone have any ideas on this? Many thanks.


    Monday, September 17, 2007 5:35 PM

Answers

  • The WSDL should define the headers, that's all there is to it.

     

     

    Tuesday, September 18, 2007 5:00 AM
    Moderator

All replies

  • The WSDL should define the headers, that's all there is to it.

     

     

    Tuesday, September 18, 2007 5:00 AM
    Moderator
  • Yes it should, but if it doesn't? Just because it's best practice to define that in the WSDL doesn't mean that people will. For those who choose not to explicitly define their header requirements (and by doing so make things more difficult for the rest of us) how does VS and .NET allow us as software developers add the required headers in order to accomplish this?
    Wednesday, October 24, 2007 6:18 PM
  • It's not just "best practice", in my opinion. The WSDL is meant to completely describe the contract between the client and the service. If the contract is incomplete, then the communication cannot be expected to work.

     

    If some piece of code between the client and service wants to add and remove headers, that's fine; the client wouldn't be sending the headers, and the service wouldn't be receiving them. One way to do this is through SoapExtensions. An extension on the client and one on the server can add and remove the headers, and since they're just talking to each other using the headers, neither the client nor server (nor the WSDL) need to know anything about the headers.

     

    But if the client itself is required to use the headers, or if the service is required to use the headers, then the WSDL must describe them.

     

     

    Thursday, October 25, 2007 10:52 AM
    Moderator
  • Hey,

     

    Even if not a best practise, It is still possible to pass SOAP headers without defining them in WSDL. On .Net side you can do it using SOAPExtension and SOAPExtensionAttributes. On Java side same can be achieved by having JAX-RPC handlers. There are quite a few example of it available on the web. Also, there is support for unknown SOAP headers  (http://msdn2.microsoft.com/en-us/library/hf2y839a.aspx) and I guess that might happen when a SOAPHeader is not defined in the wsdl.

     

    Regards,

    Anis

     

     

     

     

     

     

     

    Tuesday, October 30, 2007 9:06 PM
  •  Anis Kasmani wrote:

    Even if not a best practise, It is still possible to pass SOAP headers without defining them in WSDL. On .Net side you can do it using SOAPExtension and SOAPExtensionAttributes. On Java side same can be achieved by having JAX-RPC handlers. There are quite a few example of it available on the web. Also, there is support for unknown SOAP headers  (http://msdn2.microsoft.com/en-us/library/hf2y839a.aspx) and I guess that might happen when a SOAPHeader is not defined in the wsdl.

     

    That's what I said:

     

     John Saunders wrote:

    If some piece of code between the client and service wants to add and remove headers, that's fine; the client wouldn't be sending the headers, and the service wouldn't be receiving them. One way to do this is through SoapExtensions. An extension on the client and one on the server can add and remove the headers, and since they're just talking to each other using the headers, neither the client nor server (nor the WSDL) need to know anything about the headers.

    Wednesday, October 31, 2007 12:10 AM
    Moderator
  • I wish that .NET had some type of SoapHeader attribute of the Web service proxy class that is generated regardless of whether or not a WSDL defines headers.  Java Web service frameworks have been doing this for a while.

    SOAP extensions work fine if you want to add the same SOAP header with the same values, but it starts to become cumbersome if the undefined SOAP header needs a unique value generated at runtime.  If a SoapExtensionAttribute were used, then reflection would have to be used at runtime to set the attributes, which starts to cloud the code.

    Does anyone know if .NET intends to allow support for a header attribute on a generated Web service proxy class?
    Wednesday, March 04, 2009 3:34 AM
  • I don't expect any enhancements at all to ASMX web services, ever. You should be using WCF.
    John Saunders
    Use File->New Project to create Web Service Projects
    Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
    Thursday, March 05, 2009 3:00 PM
    Moderator