ASMX consume as WCF service and additional argumnet of method is HEADER, what should pass for HEADER

那年仲夏 提交于 2019-12-25 02:41:14

问题


I had consumed ASMX service in vs 2008. and at that time, calling method is look as below:

      PostTravelData(TravelTransaction)
      //NOTE: property - "TOKENID" was set before calling to this method.

Now, I have used same ASMX service into VS2012 and added as service reference so, it consumed as WCF service.

NOw, in method signature has one additional argumnet called - "HEADER". so signature looks as below:

      PostTravelData(Header,TravelTransaction OUT TravelTransactionResponse)

Please suggest me what should i pass as Header. i am not clear what should i have to pass as HEADER argument. I tried by passing direclty TOKENID value as header but still not work. Do i have to create object of type "RequestHeader" and keep argumnet as "TokenID" and then pass to the argumnet of that method ?

Below is the SOAP wsdl:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <soap:Header>
     <RequestHeader xmlns="http://www.example.com/Soa/Foundation/">
       <Headers>
        <anyType />
      <anyType />
    </Headers>
    </RequestHeader>
  </soap:Header>
 <soap:Body>
  <TravelTransaction xmlns="http://www.example.com/Soa/Foundation/">
    <TravelTransactionRequest xmlns="http://www.example.com/Soa/Foundation/MessageDefinition.xsd">
      <TravelData>
        <TravelMsg>           
        <IsExcused>boolean</IsExcused>
          <ScheduledMeetingId>int</ScheduledMeetingId>
         <Comment>string</Comment>
         <PostAttForScheduledPeriods>boolean</PostAttForScheduledPeriods>
       </TravelMsg>
        <TravelMsg>
        <IsExcused>boolean</IsExcused>
        <ScheduledMeetingId>int</ScheduledMeetingId>
        <Comment>string</Comment>
        <PostAttForScheduledPeriods>boolean</PostAttForScheduledPeriods>
            </TravelMsg>
           </TravelData>
         </TravelTransactionRequest>
       </TravelTransaction>
      </soap:Body>
   </soap:Envelope>

回答1:


As part of the namespace of the service you added there should be an object for the header.

You need to create this object, populate any properties as required and pass this as the parameter.



来源:https://stackoverflow.com/questions/21671535/asmx-consume-as-wcf-service-and-additional-argumnet-of-method-is-header-what-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!