Reputation: 334
I am trying to test Estes Express Freight API and have ran into a problem. I have the request object set up (and get expected error response back) except for the commodity part. There wsdl does not include a direct match such as commodity, basecommodity, or full commodities in their request class but just give an item as object type.
```
[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;
}
}
```
Here is my code so far. I have tried several things which only wind up being xml document not made. I do not understand how to add commodity, and full commodity items to the request object. Now with the hack, all I need to do is wrap the "fullCommodities" element around the "commodity" element. That is my only question now.
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 generated:
<?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>
Expected Fault Back:
<?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>
Upvotes: 2
Views: 407
Reputation: 40
I would create a List Like:
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];
And you should probably add a date for pickup or you will get an unknown fault.
Upvotes: 1