Presenter:Mike Taulty
This session looks at how we can program against SOAP headers from ASP.NET web services
The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video
Minute 0
Hello and welcome to the net framework and its session 1 in a series of short set and we find it and it is looking at how we can get stuff done with the net framework minus m Tolkien I work in the developer and platform group in Microsoft in the UK and in particular session and take a look at how you can process so papers out when arriving a speed network services with offering a 1 1 philosophical notes of headers around the extensibility that and they carry out of band information about the data that they are in the envelope and we can have as many headers are delightful and that the building of the self employed and processing in one of the former Nugget sessions we built a quick web service and a client I have that same code here so I have a web service if it is going to the code and abyss web service just has some single method Nicholl get employee and it returns on ploidy and it takes and identify with
Minute 1
Uses to index into the employees table in the north wind database and pull out of employees were just using standard radio gone out to get some data and finally rebuild at the instance of this employee class which is at the top of the file just as the first and last name and title a lot of quiet about it at a Consul application which does an indication and print out the data they get back so that I could look at that code and he realised that his activities as a proxy we call the method and pass the first employee in the database and right at the values now if it wanted to add some soap header process into this thing then can do is go back to Web service analyst in a class and Robertson s account and we will call this thing at that sense of information at times let s call this a timestamp header a gate and we can go and ends at that class and were just read his comments were second
Minute 2
As they take up some of my screen and were delivering in system length services protocols and to derive this timestamp header from classical soap header which lives in the framework contract to build a land and build our timestamp header we can put a method on it perhaps what was it it will store and at a time near witches and we are timestamp and we were so timestamp equals that time but now I don t have a public access from here as well as court timestamp and will have skittery inadequate timestamp and will have and set on and with the settlement if it is built header only transmit the two information in this distant request was sent or received from the World Service is not her use of this we need to go back
Minute 3
I won t service and on the Web service glass itself in a few the code we need to add and to add a variable here is closely tied timestamp header and a medical lip so that s where my timestamp gave a republic variable their hour of tight timestamp header and if I want that stands soap header variable or soap header in terms of XML to go backwards and forwards in my message do I need to come to mind wet method and attribute it with a soap header attribute and carry and once again I need to go and bring in that system Web services protocols thatis much spring and here and Kate have just dropped in to coach the second so I put on here and a soap header at Italy to provide the name of the variable I ve already forgotten what I call that my timestamp should get that right my
Minute 4
Timestamp onto this onto this attribute is that tells to make this thing I can also do things like specifying in which direction this header travels so I could say that for instance that this particular head travels in the direction of not having going in and out comes into the method and it was back out of the method gain so I ve added the singer s builder Steve we got that wrong hand He did so hard to get anything right in the first instance which are sometimes articles value than just my mistake and we got that term built now to figure back to the client at this point and updated its Web reference in case you go an update this thing just go to the Intel as a fixer and in the client code now when we make this call across the waves
Minute 5
Decision to populate them on the proxy the timestamp had a value to this is the so telephone across the wire and let s say that equals new timestamp header and notice of the code we wrote on the server side and play has not been transported across the clients if you look at the proxy service is very important to realise that the proxy of the timestamp header you can see just how the public daytime had none of that code of the road has been transmitted because this is just in based on the whistle document and was the document as anything about coded assessment of eczema to everyone to populate this thing we can say might proxy timestamp had a value timestamp equals daytime their and that will then make sure that this property before it serialise as XML to rebuild at this point as to rebuild
Minute 6
Okay go ahead and run the soap trace tool which we can get from these soap Toolkit still download that from amnesty ends with a far new trace listen on port 8080 me direct or 82 tracing their hand is going to ever closer that involves a tool in this situation so what has changed proxy to set its URL to be the local host 88 he asked the service is called anyone that has an axe and strange name for it does build that hand let s run and the messages are as follows like it did before what really hoping to see in the tracing tool AAs that had has been transported for us so noticed that it has and that we went to grass out with a particular types that had and we came back with a particular timestamp header and naturally that is stored in the soap header section of our envelope as opposed
Minute 7
Do so boggy section of our envelope down people we shall fight it was thought that the timestamps going back from services as a Byzantine studies came in as a throwback to the service over the second and unaltered that he went into the service code here and just before we do the return if we change the time stamp had in Kent and rebuild and run again and we should see that we get a service timestamp of the message comes back this times is that the dress messages we got a problem with tracing relatives have another go at that is run through that again back to the tracing death to the sun and you can see that he had traced a time that is going in a subtly different from the trace time on the way back to acid than some satiety processing this request Gazeley Centre I had in both directions what we didn t do was
Minute 8
Check to see whether the header was actually there on I does blithely went ahead and access this heading year and a check to see whether it was coming in on now you ll notice if you look at the documentation for soap header attribute you will see that there is a member that we can set here called required to specify whether a header is required on a vaccine net framework 1 1 this thing doesn t do anything for you again so that is no good going claimed that an better off the remark that it stands if you needed to check for the presence of the header you can always come in here and say okay if my timestamp and is null then the guy hasn t provided the header and you can throw something signed letters of the arbitrary and I can wear original header and then I m not happy as if we rebuild and go back to the client first perhaps and just take off so that the client doesn t let you send a header that s just common lack of effort I can
Minute 9
Decline is no longer sending a header that is run code and we should see that my exceptional service I get serialised as a soap fault comes back to the client retail is an exceptionally conceived the exception just about where was the head of its most resoundingly so that s kind of nice and service can check the headers that is expecting a client did not provide however there s something more important review in soap header processing and that s really more around than one of the client sends you a header that you don t understand that I gave there when we look at soap headers there is a subversion in mechanism is so such that if I send you an envelope with a set of headers in their some of those headers might be really important to me as a centre and some of them might not be and the ones the really important to me I can as he specified that the next person in the chain personally received as a message
Minute 10
Understand the header gave strike if they look I m sending you are heading here you really have to understand that day if you don t understand the header you do not process the message because thing to go seriously wrong so let s quit here and reverse the scenario at the moment we ve got a client not sending a message that had a rather better service requires that switch this around a little things presently work in the first instance must get back to a working scenarios will just take them out and start sending the the header across there again I am the server side would make things a little simpler again so will take at this check so the service is no longer saying that you have to send a header if you send it that s fine if you don t that s fine to do special things work like that before and that so that s great now the interesting thing is if we now reverse as I say the situation or if the client sends
Minute 11
Service header that the service wasn t expecting it really waited to reproduce this essentially a moment we ve got a client which is sending a header so let s go over to the service and make it such that the service is no longer expecting that had so let s take that off at the service does expect that heparin will and will just don t comment out any touching of the header there is one different rebuild at this point and run then the code still works as a kind of okay no problem without the client is now sending ahead of that service does not understand however what if the client now was to say that the particular header is very important and gay and must be understood to the client is no say I m sending you something important don t just ignore this if you don t understand the
Minute 12
You should set me back a fault let s run other finds it at the league client sent ahead and we ve must understand is that the service is not understand it and therefore we ve got back this exception and saying we didn t understand header however if we take a look at this and other bit more detail let s just start another debugging session and this time at all to do but the service allows the butler service and let source of the bug climbed again to a client sends a message to the service notice what is happening here the service code is running short of that may well essentially my service method here is processing a soap message with a header on it as martyrs must understand and the service does not understand the header but it s running the code anyway now my case the code may not really matter because just doing a read if it isn t an update that probably would have is that if we run from here
Minute 13
Method returns will get the exception but in many cases the damages can have already been done the new service is run and it s executed code to this may well normally be not what we want to happen so what can you do in order to get yourself around this well associates the art that provides another good functionality that you can make use of if we go back to our service and what I d do it is over and the service code run at an array to make an array here unknown headers and will call it on loans and care and onto this witness that he what we ll do is add soap powder on loans and can do what we can do that is the net will give to us any headers that we haven t explicitly mentioned in attribute like this and it will populate the unknown headers collection for us so in
Minute 14
Arrested here what we can do we can save each soap unknown header in the unknown is how much have preferred a 50 hour week and say if they had must be understood ago than in our case here we don t have any headers that we understand just at the moment so we ll set they understand to be faults which would actually be the default setting anyway for around headers that aren t explicitly listed up here already setting it is the explicit and what we say is if we get any headers in here that must be understood that we didn t understand that the central issue distrust of an exception now we can only do that explicitly here so we could throw an exception from here or we could do something like sector are blue flag is that so problems day at this point we have a problem and we can say if no problem
Minute 15
Problem then we go GHQ co here and has it to do it that way because when we returned from this method AST that there is going to look at all these stubborn and headers check must understand against it understand and yesterday they don t lineout they started throwing exception for us so if we look at this again in his rebuild will happen this time prosecuting at that server side code again the certificate there set a breakpoint antibody at data were debugging on the service I got on the client side and when we run across the affair notice what happens it has become known we don t have a problem but we go through unknown headers semi final that we didn t understand so now we have a problem we don t execute service code and if we run will still get the exception saying sorry and we didn t understand that header
Minute 16
Does a nice work dealing with unknown headers and literature without execute code run that meant that you just summarise here what was seen in this short session we ve looked at the soap had a class and how we can derive from that and had instances of that thing to Web service glasses and a figurehead is transported backwards and forwards to and from Web services we see how we can also pick up a raise of unknown headers things that we were quite expecting through use of the soap unknown header class and finally to take a look at what we need to do around her dealing with must understand headers and also setting did understand property to say whether week we got the message of that whether we knew what to do where can you go to get more information on Web services well probably the best place to start would be MSDN developer Santos and that s just MSDN Microsoft com and services all one word there is some
Minute 17
It s never there in the section on the left and cycled understanding Web services are some really brilliant articles equally there to get a good picture Anonymous area and if the something is he specifically in this session only thinking hang on an a lot more information on that there feel free to drop him a line and told him Microsoft com has a seven screen their drop I ll drop in response other than that I look forward to hearing seeing you next time a veteran of the Lisney
Click here to go to original video page
Thursday, July 24, 2008
Video: Working with SOAP headers in ASP.NET Web Services
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment