WCF不发送所有数据

时间:2011-06-02 20:30:04

标签: wcf soap

我已经设置了我的WCF客户端来通过Fiddler代理,这样我就可以捕获和分析流量。事实证明,我的WCF客户端没有发送我已经初始化的所有参数。

我初始化的一些参数未被发送。一个例子对我来说非常关键是lineOfBusinessList数组中的lineOfBusiness。

我已将以下代码分为3个部分,我的WCF客户端,Fiddler拦截的soap消息以及我希望我的WCF客户端发送的soap消息。

我的WCF客户端

class Program
    {
        static void Main(string[] args)
        {

            GetProductAvailability();
        }

        public static void GetProductAvailability()
        {
            ProductAvailabilityResponseType response;
            using (ProductAvailabilityServicePortTypeClient client = new ProductAvailabilityServicePortTypeClient("ProductAvailabilityServicePortQSPort"))
            {
                client.ClientCredentials.UserName.UserName = "username";
                client.ClientCredentials.UserName.Password = "password";
                 ProductAvailabilityRequestType request = new ProductAvailabilityRequestType
                {
                    requestHeader = GetRequestHeader(),
                    serviceAddress = GetServiceAddress(),
                    responseFilterCriteria = GetFilterCriteria()
                };

                response = client.getProductAvailability(request);
            }

            if (response != null)
            {

            }
            //return null;
        }

        private static RequestHeaderType GetRequestHeader()
        {
            return new RequestHeaderType
            {
                customerInteractionType = ChannelType.WebSelfServe,
                serviceRequestUserId = "55555", //not sure, ask stevenson
                serviceConsumer = ServiceConsumerToolType.Emily,
                serviceRequestTimestamp = DateTime.Now,
                language = LanguageType.English,
                referenceID = "A24T34H3" //ask stevenson if this is necessary
            };
        }

        private static ServiceAddressSearchType GetServiceAddress()
        {
            return new ServiceAddressSearchType
            {
                addressID = "000622060",
                address = new AddressType
                {
                    provinceOrState = new ProvinceOrStateType { type = ProvinceOrStateValueType.ON }
                }
            };
        }
        private static ProductAvailabilityFilterType GetFilterCriteria()
        {
            return new ProductAvailabilityFilterType
            {
                serviceSupportInfoOnly = false,
                customerSegment = CustomerSegmentType.Residential,
                channelList = new ChannelType[1] { ChannelType.WebSelfServe },
                lineOfBusinessList = new LineOfBusinessProductType[1] {
                     new LineOfBusinessProductType{ lineOfBusiness = LineOfBusinessType.Internet }
                 },
                oneBillOffers = false,
                satelliteTechnicianRequired = false,
            };
        }
    }

实际发送的是什么:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <ActivityId CorrelationId="ab64c2a1-7e32-448c-8d64-80fead66e566" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">cb08f434-ec5e-409e-a550-a0826739aa94</ActivityId>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <getProductAvailability xmlns="ca/bell/oms/autotype/productavailability">
      <requestHeader>
        <customerInteractionType xmlns="ca/bell/oms/autotype/omscommonrequest">WebSelfServe</customerInteractionType>
        <serviceRequestUserId xmlns="ca/bell/oms/autotype/omscommonrequest">55555</serviceRequestUserId>
        <serviceConsumer xmlns="ca/bell/oms/autotype/omscommonrequest">Emily</serviceConsumer>
        <serviceRequestTimestamp xmlns="ca/bell/oms/autotype/omscommonrequest">2011-06-02T16:26:13.4639736-04:00</serviceRequestTimestamp>
        <language xmlns="ca/bell/oms/autotype/omscommonrequest">English</language>
        <referenceID xmlns="ca/bell/oms/autotype/omscommonrequest">A24T34H3</referenceID>
      </requestHeader>
      <serviceAddress>
        <addressID>000622060</addressID>
        <address>
          <provinceOrState xmlns="ca/bell/oms/autotype/omscommon"/>
        </address>
      </serviceAddress>
      <responseFilterCriteria>
        <serviceSupportInfoOnly>false</serviceSupportInfoOnly>
        <channelList>
          <channel>WebSelfServe</channel>
        </channelList>
        <lineOfBusinessList>
          <lineOfBusinessProduct/>
        </lineOfBusinessList>
      </responseFilterCriteria>
    </getProductAvailability>
  </s:Body>
</s:Envelope>

SOAP期望我期待我的WCF客户端发送:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="ca/bell/oms/autotype/productavailability" xmlns:oms="ca/bell/oms/autotype/omscommonrequest" xmlns:oms1="ca/bell/oms/autotype/omscommon">
   <soapenv:Header/>
   <soapenv:Body>
      <prod:getProductAvailability>
            <oms:requestHeader>
                <oms:customerInteractionType xmlns:n2 = "ca/bell/oms/autotype/omscommonrequest">WebSelfServe</oms:customerInteractionType>
                <oms:serviceRequestUserId xmlns:n3 = "ca/bell/oms/autotype/omscommonrequest">55555</oms:serviceRequestUserId>
                <oms:serviceConsumer xmlns:n4 = "ca/bell/oms/autotype/omscommonrequest">Emily</oms:serviceConsumer>
                <oms:serviceRequestTimestamp xmlns:n5 = "ca/bell/oms/autotype/omscommonrequest">2010-11-30T11:27:08.431-05:00</oms:serviceRequestTimestamp>
                <oms:language xmlns:n6 = "ca/bell/oms/autotype/omscommonrequest">English</oms:language>
                <oms:referenceID xmlns:n7 = "ca/bell/oms/autotype/omscommonrequest"></oms:referenceID>
            </oms:requestHeader>
         <prod:serviceAddress>
            <prod:addressID>000622060</prod:addressID>
            <prod:address>
               <oms1:provinceOrState>
                  <oms1:type>ON</oms1:type>
               </oms1:provinceOrState>
            </prod:address>
         </prod:serviceAddress>
         <prod:responseFilterCriteria>
            <prod:serviceSupportInfoOnly>false</prod:serviceSupportInfoOnly>
            <prod:customerSegment>Residential</prod:customerSegment>
            <prod:channelList>
               <prod:channel>WebSelfServe</prod:channel>
            </prod:channelList>
            <prod:lineOfBusinessList>
               <prod:lineOfBusinessProduct>
                  <prod:lineOfBusiness>Internet</prod:lineOfBusiness>
               </prod:lineOfBusinessProduct>
            </prod:lineOfBusinessList>
            <prod:oneBillOffers>false</prod:oneBillOffers>
        <prod:satelliteTechnicianRequired>false</prod:satelliteTechnicianRequired>
         </prod:responseFilterCriteria>
      </prod:getProductAvailability>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

猜测,您在某些DataContract属性上缺少DataMember属性。