Estes Express Api 版本 4.0 报价

Estes Express Api Version 4.0 Rate Quote

我正在尝试测试 Estes Express Freight API,但 运行 遇到了问题。除了商品部分,我已经设置了请求对象(并得到预期的错误响应)。 wsdl 在他们的请求中不包括商品、基础商品或完整商品等直接匹配 class,而只是将项目作为对象类型提供。

    ```
      
       

 [System.Xml.Serialization.XmlElementAttribute("baseCommodities", 
        typeof(BaseCommoditiesType))]
        [System.Xml.Serialization.XmlElementAttribute("fullCommodities", 
        typeof(FullCommoditiesType))]
        public object Item {
            get {
                return this.itemField;
            }
            set {
                this.itemField = value;
            }
        }

[System.Xml.Serialization.XmlElement("commodity", typeof(FullCommodityType))]//added to request class recently
       
        public object Items
        {
            get
            {
                return this.itemsField;
            }
            set
            {
                this.itemsField = value;
            }
        }
    
  
```

到目前为止,这是我的代码。我已经尝试了几件事,但最终都没有制作 xml 文件。我不明白如何向请求对象添加商品和完整的商品项目。现在有了技巧,我需要做的就是将“fullCommodities”元素包裹在“commodity”元素周围。这是我现在唯一的问题。

   

static void Main(string[] args)
    {
        RateQuoteService service = new RateQuoteService() ;

        AuthenticationType authentication = new AuthenticationType();
        authentication.user = "xxxxxxxx";
        authentication.password = "xxxxxx";
        service.auth = authentication;

        rateRequest request = new rateRequest();
        rateQuote quote = new rateQuote();
        
        request.requestID = generateID();//just guid value for now
        
        request.account = "xxxxxxx";

        PointType origin = new PointType();
        origin.city = "Shelby TownShip";
        origin.postalCode = "48315";
        origin.stateProvince = "MI";
        origin.countryCode = "US";
        request.originPoint = origin;

        PointType destination = new PointType();
        destination.city = "Fenton";
        destination.postalCode = "48430";
        destination.stateProvince = "MI";
        destination.countryCode = "US";
        request.destinationPoint = destination;

        request.payor = "S";
        request.terms = "P";

        PickupType pickUP = new PickupType();
        request.pickup = pickUP;
        request.declaredValue = 1000.00M;
        request.declaredValueSpecified = true;
 
        request.stackable = YesNoBlankType.N;//enum
        request.stackableSpecified = true;
        request.linearFeet = "80";
        request.foodWarehouse = "other";

        request.declaredValueWaived = YesNoBlankType.N;//enum
        request.declaredValueWaivedSpecified = true;
        
        FullCommoditiesType fcom = new FullCommoditiesType();//just commodity property
        FullCommodityType fcomtypes = new FullCommodityType();//all other properties
       
        DimensionsType dim = new DimensionsType();
        dim.length = "75";
        dim.width = "50";
        dim.height = "25";

        fcomtypes.@class = 70.0M;
        fcomtypes.weight = "500";
        fcomtypes.pieces = "2";
        fcomtypes.pieceType = PackagingType.PT;
        fcomtypes.classSpecified = true;
        fcomtypes.dimensions = dim;
       
        //fcom.commodity  = ????
        //request.Item = ????//I'm assuming fcomtypes but dosent work

request.Items = fcomtypes;  //Hack - Now this adds what I need to the request object
        
        //request.Item = fcomtypes as FullCommodityType;//dont work either

        quote = service.getQuote(request);

        

   






    }

XML 生成:

 <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Header>
              <auth xmlns="http://ws.estesexpress.com/ratequote">
                     <user>xxxxxx</user>
                     <password>xxxxxxxx</password>
              </auth>
       </soap:Header>
       <soap:Body>
              <rateRequest xmlns="http://ws.estesexpress.com/schema/2019/01/ratequote">
                     <requestID>5fdbdbeedf474a439a54559750c2c5ea</requestID>
                     <account>xxxxxxx</account>
                     <originPoint>
                           <countryCode>US</countryCode>
                           <postalCode>48315</postalCode>
                           <city>Shelby TownShip</city>
                           <stateProvince>MI</stateProvince>
                     </originPoint>
                     <destinationPoint>
                           <countryCode>US</countryCode>
                           <postalCode>48430</postalCode>
                           <city>Fenton</city>
                           <stateProvince>MI</stateProvince>
                     </destinationPoint>
                     <payor>S</payor>
                     <terms>P</terms>
                     <pickup>
                           <date>0001-01-01</date>
                     </pickup>
                     <declaredValue>1000.00</declaredValue>
                     <declaredValueWaived>N</declaredValueWaived>
                     <stackable>N</stackable>
                     <linearFeet>80</linearFeet>
                     <foodWarehouse>other</foodWarehouse>
                     <commodity>
                           <class>70.0</class>
                           <weight>500</weight>
                           <pieces>2</pieces>
                           <pieceType>PT</pieceType>
                           <dimensions>
                                  <length>75</length>
                                  <width>50</width>
                                  <height>25</height>
                           </dimensions>
                           <description>test</description>
                     </commodity>
              </rateRequest>
       </soap:Body>
</soap:Envelope>

预期故障回复:

 <?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>Schema validation error</faultstring>
            <detail>
                <rat:schemaError xmlns:rat="http://ws.estesexpress.com/ratequote">
                    <rat:error>Expected elements 'baseCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote fullCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote' before the end of the content in element rateRequest@http://ws.estesexpress.com/schema/2019/01/ratequote</rat:error>
                    <rat:error>Expected elements 'baseCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote fullCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote' instead of 'commodity@http://ws.estesexpress.com/schema/2019/01/ratequote' here in element rateRequest@http://ws.estesexpress.com/schema/2019/01/ratequote</rat:error>
                </rat:schemaError>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

我会像这样创建一个列表:

 List<FullCommodityType> productDesc = new List<FullCommodityType>();
    
 productDesc.Add(new FullCommodityType()
 {
     @class = 70,
     classSpecified = true,
     weight = "500",
     pieces = "2",
     pieceType = PackagingType.PT,                        
     dimensions = dim
 });

 List<FullCommoditiesType> products = new List<FullCommoditiesType>();

 products.Add(new FullCommoditiesType()
 {
     commodity = productDesc.ToArray()    
 });                 

 request.Item = products[0];

并且您可能应该添加取件日期,否则您将遇到未知故障。