将标头数据添加到我的Web服务请求。 [英] Adding a header data to my webservice request.
问题描述
我已经为我的Web项目添加了一个服务引用,只需创建一个程序集并右键单击它以添加服务引用...现在我只提供WSDL路径并创建一个服务引用。
我能够从这个引用的对象中获取所有方法名称和参数类型。即使我能够成功调用该服务。
例如:
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 :
SecurityProcessHandler objProcessHandler = new SecurityProcessHandler();
string objReturn = objProcessHandler.getUserDataForLogin(objInput);
我的问题是我现在需要在调用服务时向请求添加标题信息,而 SOAP 格式的标题信息如下:
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:
<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.
推荐答案
我不确定这是不是你的意思。但您可以通过以下方式为SOAP标头创建安全令牌:
I''m not sure if this is what you mean. But you can create a security token for the SOAP header via:
// Create the WS-Security token for the SOAP header
UsernameToken userToken = new UsernameToken(uid, pswd, PasswordOption.SendPlainText);
service.RequestSoapContext.Security.Tokens.Add(userToken);
这篇关于将标头数据添加到我的Web服务请求。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!