Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have added a service reference to my Web Project by just creating an assembly and right clicking on it to "Add a service Reference..." now I just provide the WSDL path and created a service reference.

I am able to get all the method names and the parameter type from the object of this reference.Even I am able to successfully invoke the service.

For Example :
C#
SecurityProcessHandler objProcessHandler = new SecurityProcessHandler();
string objReturn = objProcessHandler.getUserDataForLogin(objInput);


My problem is that I now need to add a header info to the request while invoking the service and the header info in SOAP format is as follows:

XML
<soapenv:Header>
    <wss:Security
    xmlns:wss="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wss:UsernameToken>
            <wss:Username>SRVNEST</wss:Username>
        </wss:UsernameToken>
    </wss:Security>
    <ent:EnterpriseContext
  xmlns:ent="http://contracts.it.nednet.co.za/Infrastructure/2008/09/EnterpriseContext">
       <ent:ContextInfo>
            <ent:ExecutionContextId>568e7eee-8b24-4865-9071-bad8506e3e61</ent:ExecutionContextId>
        </ent:ContextInfo>
        <ent:RequestOriginator>
            <ent:MachineIPAddress>10.58.42.55</ent:MachineIPAddress>
            <ent:UserPrincipleName>SRVNEST</ent:UserPrincipleName>
            <ent:MachineDNSName>nedicad</ent:MachineDNSName>
            <ent:ChannelId>0</ent:ChannelId>
        </ent:RequestOriginator>
        <ent:InstrumentationInfo>
            <ent:ParentInstrumentationIdElem>f44c492d-e57f-4f39-b549-74f23b61dfe7</ent:ParentInstrumentationIdElem>
        </ent:InstrumentationInfo>
    </ent:EnterpriseContext>
</soapenv:Header>



Now I don't know how to add a header info to my service call.
Is it possible to add header info to my service? I tried in google but with no success.
Posted

1 solution

I'm not sure if this is what you mean. But you can create a security token for the SOAP header via:

C#
// Create the WS-Security token for the SOAP header
UsernameToken userToken = new UsernameToken(uid, pswd, PasswordOption.SendPlainText);
service.RequestSoapContext.Security.Tokens.Add(userToken);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900