Link to home
Start Free TrialLog in
Avatar of d0nMaTTi
d0nMaTTiFlag for Finland

asked on

How to send soadheader

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
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of d0nMaTTi

ASKER

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.

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?
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.
the link of example tell part of my problem. It was a good example from usernametoken but it didn't solve whole problem