web services - Calling SOAP API with Complex Type in C# -
i'm new .net, apologize in advance if definition of problem not accurate.
i'm attempting consume soap web service , i'm having problem constructing complex type element called deliveryroutingrequestentries.
i have added wsdl using service reference, here part of wsdl:
<wsdl:operation name="validatedeliveryaddress"> <soap:operation soapaction="" style="document" /> <wsdl:input name="validatedeliveryaddress"> <soap:body use="literal" /> </wsdl:input> <wsdl:output name="validatedeliveryaddressresponse"> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <xs:complextype name="deliveryroutingrequestentries"> <xs:sequence> <xs:element maxoccurs="unbounded" name="deliveryroutingrequestentry" type="tns:delroutingrequestentry" /> </xs:sequence> </xs:complextype> <xs:complextype name="delroutingrequestentry"> <xs:sequence> <xs:element minoccurs="0" name="addressvalidationrequired" type="xs:boolean" /> <xs:element name="customer" type="tns:customer" /> <xs:element name="parcel" type="tns:parcel" /> <xs:element minoccurs="0" name="services" type="tns:services" /> <xs:element minoccurs="0" name="senderaddress" type="tns:senderaddress" /> <xs:element minoccurs="0" name="productcode" type="xs:decimal" /> <xs:element name="expecteddespatchdate" type="xs:date" /> <xs:element minoccurs="0" name="requireddate" type="xs:date" /> <xs:element minoccurs="0" name="countryoforigin" type="xs:string" /> <xs:element minoccurs="0" name="warehouseno" type="xs:decimal" /> <xs:element minoccurs="0" name="carriercode" type="xs:string" /> <xs:element minoccurs="0" name="deliverymethod" type="xs:string" /> <xs:element minoccurs="0" name="multiplepartsid" type="xs:string" /> </xs:sequence> </xs:complextype>
here attempt call validatedeliveryaddress:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using hermeswebservice; public partial class _default : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void button1_click(object sender, eventargs e) { routingwebserviceclient objhermeswebservice = new routingwebserviceclient(); objhermeswebservice.clientcredentials.username.username = "abababab"; objhermeswebservice.clientcredentials.username.password = "abababab"; deliveryroutingrequest objroutingrequest = new deliveryroutingrequest(); objroutingrequest.clientid = "abab"; objroutingrequest.clientname = "abab"; objroutingrequest.userid = "ababab"; objroutingrequest.sourceofrequest = "ababab"; delroutingrequestentry objreqentry = new delroutingrequestentry(); customer objcust = new customer(); objcust.customerreference1 = "12345"; address objadr = new address(); objadr.streetname = "7 bridge street"; objadr.addressline1 = "london heathrow airport"; objadr.city = "london"; objadr.region = "hounslow"; objadr.postcode = "aba aba"; objadr.countrycode = "gb"; parcel objpcl = new parcel(); objpcl.weight = 100; objpcl.length = 0; objpcl.width = 0; objpcl.depth = 0; objpcl.girth = 0; objpcl.combineddimension = 0; objcust.address = objadr; objreqentry.customer = objcust; objreqentry.parcel = objpcl; objroutingrequest.deliveryroutingrequestentries = objreqentry; (i receive error here stating: cannot implicitly convert type 'hermeswebservice.delroutingrequestentry' 'hermeswebservice.delroutingrequestentry[]') var x = objhermeswebservice.validatedeliveryaddress(objroutingrequest); } }
the problem have can't add customer, address , parcel objroutingrequest can included in request.
hope makes sense, let me know if additional information needed.
(just move answer here:)
got error @ : objroutingrequest.deliveryroutingrequestentries = objreqentry;
,
should pass array:
objroutingrequest.deliveryroutingrequestentries = new [] {objreqentry};