Re: Inserting a SOAP Header in a client request

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dilip Krishnan (dkrishnan_at_NOSPAM.geniant.com)
Date: 01/13/05


Date: Thu, 13 Jan 2005 09:22:04 -0800

Hello john,
    I dont see the difference in what you call the second option and the
third option. What you seem to be missing is overriding the chain stream
and writing to the stream (which I gather you dont wish to do). The problem
with your code is .. yes you're using the soap object model to add the header
but you've failed to modify the stream by writing that information back into
the stream. Also have you considered using WSE? and also are you sure the
java service is not using WS-Security? If it is, you would need to send standard
username tokens as opposed to a custom auth header

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com

> I have a C#/.Net 1.1 client talking to a Java based web service. I
> need to
> insert a soap header on the client side which is expected on the
> server side.
> Currently, the Java ws provider, Axis, does not support automatic
> wsdl
> generation of custom headers so the wsdl has no information regarding
> the
> required header.
>
> I've read through a lot of material and managed to get a workable
> solution but it is far from ideal.
>
> I created a new AuthHeader:SoapHeader class and updated the client ws
> proxy to make use of the new header. This worked but I want to avoid
> having to modify tool generated code. I don't want to touch the .Net
> wsdl.exe generated ws proxy.
>
> One other solution may be to modify the stream via my own
> SoapExtension class. Problem is that requires working at a low level
> on the stream. Why should I have to do that when .Net provides a rich
> SOAP API?
>
> I would think I should be able to simply insert my own SoapHeader into
> the SoapMessage via SoapExtension.ProcessMessage(). I have tried this
> approach without success. I get a System.InvalidOperationException
> upon attempted serialization of the SoapMessage. The error is, "The
> type SimpleWSClient.AuthHeader was not expected. Use the XmlInclude or
> SoapInclude attribute to specify types that are not known statically."
> It seems like this approach should work. I assumed that a SoapHeader
> object would already know how to serialize itself if it contains only
> basic types.
>
> My SoapHeader and SoapExtension classes below:
>
> using System;
> using System.Xml.Serialization;
> using System.Web.Services.Protocols;
> namespace SimpleWSClient
> {
> public class AuthHeader : SoapHeader
> {
> private string userName;
> private string password;
> public AuthHeader()
> {
> }
> public AuthHeader(string user, string pwd)
> {
> UserName = user;
> Password = pwd;
> }
> public string UserName
> {
> get { return userName; }
> set { userName = value; }
> }
> public string Password
> {
> get { return password; }
> set { password = value; }
> }
> }
> }
>
> using System;
> using System.Web;
> using System.Web.Services;
> using System.Web.Services.Protocols;
> using System.Xml;
> using System.Xml.Serialization;
> namespace SimpleWSClient
> {
> /// <summary>
> /// SOAP Extension that checks the SOAP Header for a username and
> password
> /// and does the necessary authentication and authorization.
> /// </summary>
> public class UsernamePasswordSoapExtension : SoapExtension
> {
> public override object GetInitializer( Type serviceType )
> {
> return null;
> }
> public override object GetInitializer( LogicalMethodInfo methodInfo,
> SoapExtensionAttribute attribute )
> {
> return null;
> }
> public override void Initialize( object initializer )
> {
> }
> public override void ProcessMessage( SoapMessage message )
> {
> if (message.Stage == SoapMessageStage.BeforeSerialize)
> {
> SecurityContext context = SecurityContext.getInstance();
> AuthHeader soapHeader = new AuthHeader(context.UserName,
> context.Password);
> SoapClientMessage scm = (SoapClientMessage)message;
> SoapHeaderCollection headers = scm.Headers;
> headers.Add(soapHeader);
> }
> }
> }
> }
> This last approach is what I am after. It would allow me to insert a
> custom SoapHeader using a high-level Soap API without having to inject
> custom code into a tool generated ws proxy.
>
> Is it possible to make this last approach work or am I forced to work
> with the first two options?
>
> Thanks.
>



Relevant Pages

  • Re: NetworkStreams impractical?, Buffering NetworkStreams, how?
    ... > appear as a stream. ... The header can contain whatever ... but should include the length of the packet which is to follow. ... > some memory buffer in your class. ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: Object serialization and NetworkStream - extraneous characters in output
    ... when you retrieve the stream and try reading the ... you found there is an additional header "o;?" ... As for the problem you mentioned, I think it is likely due to the encoding ... ASCII stream won't have such a header). ...
    (microsoft.public.dotnet.framework)
  • Re: Segmented Data Over Sockets
    ... Keep reading bytes until you receive 0. ... only difference here is now your adding boundaries to the stream. ... prepend an int length in the header which says how many data bytes to follow ... |> each byte of the local structure on the receiving end, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Capture to AVI question
    ... > stream to be able to playback the stream? ... It depends on how much info the writer put in the header ... rebuild the index (this one is tough, ... // a dot angeli at psynet dot net ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Inserting a SOAP Header in a client request
    ... my SoapHeader object has a GetXml() implementation that is not public? ... How do I write the header to the stream in the correct place? ...
    (microsoft.public.dotnet.framework.webservices)