How to send soadheader

d0nMaTTi
d0nMaTTi used Ask the Experts™
on
I have webservice which use third-party's webservice component. This has method
getSimpl
I shoud send identifiation information (username,passwor,timestamp,checksum) inside soapheader but I've no idea how to accomplish it .

Format of soapheader shoul be :

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <SOAP-ENV:Header>
  <wsse:Security
   xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
     xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <wsse:UsernameToken>
    <wsse:Username>XXXXXXXXXXXX</wsse:Username>
    <wsse:Password
   Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">NNNNNNNN</wsse:Password>
   </wsse:UsernameToken>
  </wsse:Security>
  <cmn:timeStamp
   xmlns:cmn="http://www.somebody.fi/XMLSchema/test_4.02.xsd">2010012714454800+0200000</cmn:timeStamp>
  <cmn:checkSum
   xmlns:cmn="http://www.somebody.fi/XMLSchema/test_4.02.xsd">48D703C2E5250EBB6C19701F98435196</cmn:checkSum>
 </SOAP-ENV:Header>
 <SOAP-ENV:Body>
  <getSimpl
    xmlns="http://www.somebydy.fi/test/">
   <ns1:request xmlns:ns1="http://www.someboyd.fi/XMLSchema/test_Request_4.02.xsd">
    <ns1:endUser>testtest</ns1:endUser>
    <ns1:personId>010100-123D</ns1:personId>
    <ns1:purpose>1</ns1:purpose>
    <ns1:searchName>Testi</ns1:searchName>
    <ns1:languageCode>FI</ns1:languageCode>
    <ns1:target>TAP1</ns1:target>
    <ns1:model>SIMP1</ns1:model>
   </ns1:request>
  </getSiml>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
getSimp method has requesttype parameter which has enduser,personid .. fields and
the format of method is:
responseclass=getsimpl(requesttypeclass).
How to create this kind of soap header AND how to definat my  own webmethon (which runs getsiml) vso that soapheader with identificatio-information and method-parameters will be passed on server????

Matti Niskasaari
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Principal Solutions Architect
Top Expert 2006
Commented:
I believe you are  using .NET platform, based on the .net version you are using there are two different WSE version available which stand for Web Services Security Extension.

The SOAP header shown in the above SOAP msg is WS-UserNameToken which is a standard way to pass on the credentials across webservices.

See this for more details
http://www.nxtgenug.net/Article.aspx?ArticleID=57

Author

Commented:
I'm using .NET 2008 and wse3 is installed on my machine. Those link's example
doesn't work on vs 2008 (framework 3.5) because of method: SetClientCredential , I can't find it.
There is a ClientCredentials property which is readonly.
I've added webrefence named ThidParty and that has class consumer_4_02
so if I've understood right the links example
 (ObjectService.ServiceWse swe = new ObjectService.ServiceWse();swe.SetClientCredential(ut);)

it would go: Thirdpary.consumer_4_02 cons = new ThirdParty.consumer_4_02();
cons has ClientCredentials property but not  SetClientCredential
I'm doubtful that i've understood something wrong.

Author

Commented:

Apparently .NET convert's reference-class from webservice and this class inherits namespace:
System.Web.Services.Protocols.SoapHttpClientProtocol
When i changed it to Microsoft.Web.Services3.WebServicesClientProtocol ditto problem solve's.
Now , when i want to soapheader with elements as follows:

UsernameToken user= new UsernameToken("myusername", "mypassword", PasswordOption.SendHashed);
webservice.class on neededservice=new vebservice.class(),
neededservice.RequestSoapContext.Security.Tokens.Add(user);
neededservice.RequestSoapContext.Security.Elements.Add(new Microsoft.Web.Services3.Security.MessageSignature(user)); //does this method create vss-security element//
//then I need to add also elements timeStamp and checkSum//
string strTimeStamp="2010020211254989+0212345"
stirng strchecSum="44545adsfgafaflktwewbdsrt642jt4ur62"
neededservice.RequestSoapContext.Add("timeStamp", strTimeStamp);
neededservice.RequestSoapContext.Add("checkSum", strcheckSum);
myanswer=neededservice.getsimpl(sameparametr)
Is this the way to create additional elements to soapheader which client (my program) sends to server?

Author

Commented:
Problem solved.
When i add elements this way:
proxy.RequestSoapContext.Security.MustUnderstand = true;
                proxy.RequestSoapContext.Security.Tokens.Add(user);
                proxy.RequestSoapContext.Security.Elements.Add(new Microsoft.Web.Services3.Security.MessageSignature(user));
                user.AnyElements.Add(xmlelementtimestamp);
                user.AnyElements.Add(xmlelementchecksum);
server  founds all needed elements from soapheader.

Author

Commented:
the link of example tell part of my problem. It was a good example from usernametoken but it didn't solve whole problem

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial