首页 新闻 会员 周边

WCF的消息头问题!

0
悬赏园豆:50 [已关闭问题]

需要在WCF客户端调用webService时在(header)信息头中加入以下内容:

          <wsse:Security mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken wsu:Id="UsernameToken-5700630" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
              <wsse:Username>username</wsse:Username>
              <wsse:UserTokenID>password</wsse:UserTokenID>
              </wsse:UsernameToken>
          </wsse:Security>

 

其中username,和passwork会变化需要传入。

 

目前使用在config中加入

    <client>
      <endpoint address="http://localhost:81/="MessageTransportBinding"
          binding="basicHttpBinding" bindingConfiguration="MessageTransportBinding" 
          contract="MessageTransportService.MessageTransportPort" name="MessageTransportPort" >
        <headers>
          <wsse:Security mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken wsu:Id="UsernameToken-5700630" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
              <wsse:Username>username</wsse:Username>
              <wsse:UserTokenID>password</wsse:UserTokenID>
              </wsse:UsernameToken>
          </wsse:Security>
        </headers>
      </endpoint>
    </client>

 

虽然实现了在消息中加入自定义的头,但是无法修改username和password的值。。。。

 

往大哥指教告诉我怎么才能按username和password的值生成相应的信息头并加入到消息的头区域。

问题补充: 添加头的问题我解决了但是又遇到新问题。。。 使用wcf做client调用java写的webservice时。。。我用system.diagnostics进行跟踪。。。然后发现竟然每次调用服务client都会发送2次请求。。。 往大哥指教这个是为什么? 一下是记录的Soap流 <?xml version="1.0" encoding="utf-8" ?> <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> <EventID>0</EventID> <Type>3</Type> <SubType Name="Information">0</SubType> <Level>8</Level> <TimeCreated SystemTime="2009-08-21T03:01:05.7013905Z" /> <Source Name="System.ServiceModel.MessageLogging" /> <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /> <Execution ProcessName="ServerPlate.vshost" ProcessID="12316" ThreadID="9" /> <Channel/> <Computer>KRAD</Computer> </System> <ApplicationData> <TraceData> <DataItem> <MessageLogTraceRecord Time="2009-08-21T11:01:05.4904665+08:00" Source="ServiceLevelSendRequest" Type="System.ServiceModel.Dispatcher.OperationFormatter+OperationFormatterMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace"> <HttpRequest> <Method>POST</Method> <QueryString></QueryString> <WebHeaders> <VsDebuggerCausalityData>uIDPo9BWha28ZeNGrb8WhRS+eJIAAAAAfrqB2mT3d0ma0Yb2h+yHnWvItZRtuDlFvy8YyPfAgBYACQAA</VsDebuggerCausalityData> </WebHeaders> </HttpRequest> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <Action s:mustUnderstand="1" xmlns="http://schemas.
krad chen的主页 krad chen | 初学一级 | 园豆:140
提问于:2009-08-20 16:47
< >
分享
其他回答(1)
0

Hi,

 我查询到一个文章,你参考一下http://stackoverflow.com/questions/893588/wcf-adding-username-to-the-message-header-is-this-secure。里面有操作MessageHeader的代码,:

using (OperationContextScope scope = new OperationContextScope(myService2.InnerChannel))
 
{
   
Guid myToken = Guid.NewGuid();

   
MessageHeader<string> messageHeader = new MessageHeader<string>(HttpContext.Current.User.Identity.Name);
   
MessageHeader untyped = messageHeader.GetUntypedHeader("token", "ns");

   
OperationContext.Current.OutgoingMessageHeaders.Add(untyped);

    lblResult
.Text = myService2.GetData(1231);
 
}
你调用Web服务,应该可以对消息做处理,代码应该类似。

 我不确定这个对你是否有参考价值http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/aa1e3c3a-be80-417e-a26e-233fe8c2ef5b

 希望对你的问题解决有帮助~

Frank Xu Lei | 园豆:1860 (小虾三级) | 2009-08-20 17:45
0

亲,请问您的问题解决了吗?

cwcls | 园豆:27 (初学一级) | 2014-07-21 11:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册