ASMX使用WCF服务,方法的附加参数是HEADER,应该为HEADER传递什么

时间:2014-02-10 07:44:11

标签: wcf web-services asmx webservice-client

我在vs 2008中使用过ASMX服务。当时,调用方法如下所示:

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

现在,我已经在VS2012中使用了相同的ASMX服务并添加为服务参考,因此它被用作WCF服务。

否则,在方法签名中有一个名为“HEADER”的附加argumnet。签名如下所示:

      PostTravelData(Header,TravelTransaction OUT TravelTransactionResponse)

请建议我作为标题传递什么。我不清楚我应该作为HEADER论证传递什么。 我尝试将direclty TOKENID值作为标题传递,但仍无法正常工作。 我是否必须创建“RequestHeader”类型的对象并将argumnet保留为“TokenID”,然后传递给该方法的argumnet?

以下是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 个答案:

答案 0 :(得分:0)

作为您添加的服务命名空间的一部分,标题应该有一个对象。

您需要创建此对象,根据需要填充任何属性并将其作为参数传递。