Issues with UPS's xml request is not valid xml - c#

Not sure if anyone has had this issue with UPS's xml api request sample but I am trying to post an xml request to receive UPS rates. I am using their request example which I have posted below. However, this is not a valid xml document because it has more than one root tag, but if I post this to UPS it goes through fine.
What to do about this? Do I need to do some C# hacking to make this work? I am at a loss.
Why would UPS give an invalid example to use for their api? Any help would be great. Thanks.
<?xml version="1.0"?> <AccessRequest xml:lang="en-US"> <AccessLicenseNumber>Your Access License</AccessLicenseNumber> <UserId>Your User Id</UserId> <Password>Your Password</Password> </AccessRequest> <?xml version="1.0"?> <RatingServiceSelectionRequest xml:lang="en-US"> <Request> <TransactionReference> <CustomerContext>Your Customer Context</CustomerContext> </TransactionReference> <RequestAction>Rate</RequestAction> <RequestOption>Rate</RequestOption> </Request> <Shipment> <RateInformation> <NegotiatedRatesIndicator/> </RateInformation> <Shipper> <Name>Shipper Name</Name> <AttentionName>Shipper Attention Name</AttentionName> <PhoneNumber>1234567890</PhoneNumber> <FaxNumber>1234567890</FaxNumber> <ShipperNumber>Your Shipper Number</ShipperNumber> <Address> <AddressLine1>Address Line 1</AddressLine1> <City>City</City> <StateProvinceCode>StateProvinceCode</StateProvinceCode> <PostalCode>PostalCode</PostalCode> <CountryCode>CountryCode</CountryCode> </Address> </Shipper> <ShipTo> <CompanyName>Ship To Company Name</CompanyName> <AttentionName>Ship To Attention Name</AttentionName> <PhoneNumber>1234567890</PhoneNumber> <FaxNumber>1234567890</FaxNumber> <Address> <AddressLine1>Address Line 1</AddressLine1> <City>City</City> <StateProvinceCode>StateProvinceCode</StateProvinceCode> <PostalCode>PostalCode</PostalCode> <CountryCode>CountryCode</CountryCode> </Address> </ShipTo> <ShipFrom> <CompanyName>Ship From Company Name</CompanyName> <AttentionName>Ship From Attention Name</AttentionName> <PhoneNumber>1234567890</PhoneNumber> <FaxNumber>1234567890</FaxNumber> <Address><AddressLine1>Address Line 1</AddressLine1> <City>City</City> <StateProvinceCode>StateProvinceCode</StateProvinceCode> <PostalCode>PostalCode</PostalCode> <CountryCode>CountryCode</CountryCode> </Address> </ShipFrom> <Service> <Code>59</Code> <Description>2nd Day Air AM</Description> </Service> <Package> <PackagingType> <Code>02</Code> <Description>UPS Package</Description> </PackagingType> <PackageWeight> <UnitOfMeasurement> <Code>LBS</Code> </UnitOfMeasurement> <Weight>5</Weight> </PackageWeight> <Dimensions> <Length>10</Length> <Width>5</Width> <Height>7</Height> </Dimensions> </Package> </Shipment> </RatingServiceSelectionRequest>
XML File 1
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>Your Access License</AccessLicenseNumber>
<UserId>Your User Id</UserId>
<Password>Your Password</Password>
</AccessRequest>
Xml File 2
<?xml version="1.0"?>
<RatingServiceSelectionRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Your Customer Context</CustomerContext>
</TransactionReference>
<RequestAction>Rate</RequestAction>
<RequestOption>Rate</RequestOption>
</Request>
<Shipment>
<RateInformation>
<NegotiatedRatesIndicator/>
</RateInformation>
<Shipper>
<Name>Shipper Name</Name>
<AttentionName>Shipper Attention Name</AttentionName>
<PhoneNumber>1234567890</PhoneNumber>
<FaxNumber>1234567890</FaxNumber>
<ShipperNumber>Your Shipper Number</ShipperNumber>
<Address>
<AddressLine1>Address Line 1</AddressLine1>
<City>City</City>
<StateProvinceCode>StateProvinceCode</StateProvinceCode>
<PostalCode>PostalCode</PostalCode>
<CountryCode>CountryCode</CountryCode>
</Address>
</Shipper>
<ShipTo>
<CompanyName>Ship To Company Name</CompanyName>
<AttentionName>Ship To Attention Name</AttentionName>
<PhoneNumber>1234567890</PhoneNumber>
<FaxNumber>1234567890</FaxNumber>
<Address>
<AddressLine1>Address Line 1</AddressLine1>
<City>City</City>
<StateProvinceCode>StateProvinceCode</StateProvinceCode>
<PostalCode>PostalCode</PostalCode>
<CountryCode>CountryCode</CountryCode>
</Address>
</ShipTo>
<ShipFrom>
<CompanyName>Ship From Company Name</CompanyName>
<AttentionName>Ship From Attention Name</AttentionName>
<PhoneNumber>1234567890</PhoneNumber>
<FaxNumber>1234567890</FaxNumber>
<Address>
<AddressLine1>Address Line 1</AddressLine1>
<City>City</City>
<StateProvinceCode>StateProvinceCode</StateProvinceCode>
<PostalCode>PostalCode</PostalCode>
<CountryCode>CountryCode</CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>59</Code>
<Description>2nd Day Air AM</Description>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
<Description>UPS Package</Description>
</PackagingType>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>5</Weight>
</PackageWeight>
<Dimensions>
<Length>10</Length>
<Width>5</Width>
<Height>7</Height>
</Dimensions>
</Package>
</Shipment>
</RatingServiceSelectionRequest>

Related

Validate XML against XSD and create log of records that failed

Have a sample XML
<persons>
<person>
<fname>John</fname>
<lname>Doe</lname>
<addresses>
<address>
<add_line1>Street</add_line1>
<zip>1234</zip>
<state>NY</state>
</address>
<address>
<add_line1>Street</add_line1>
<zip>1234</zip>
<state>PA</state>
</address>
<address>
</address>
</addresses>
</person>
</persons>
I can validate it against an XSD and I can get if it passes validation or not
Is it possible to run it through validation wherein I can get the exact record for which validation failed?
Bad XML:
<persons>
<person>
<fname>John</fname>
<lname>Doe</lname>
<addresses>
<address>
<add_line1>Street</add_line1>
<zip>1234</zip>
<state>NY</state>
</address>
<address>
<add_line1>Street</add_line1>
<zip>1234</zip>
<state>PAA</state>
</address>
<address>
</address>
</addresses>
</person>
</persons>
The above would fail state validation as state is PAA instead of PA.
So I am looking to get that state validation failed for John Doe and any other user
I can get the records used for creating the xml into a data table - not sure if it is possible to validate the records against XSD - figure the best option is to generate the xml against the xsd and create a log file of all records that failed validation.

missing prefix in soap request c# dynamic web request

I´m using the WsdlImporter to read a wsdl-file and create a dynamic web request. But if I create the request a prefix in my request is missing and the consuming web service can not handle with this request. How can I force, that the prefix will be set?
This is how the request should be:
<?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" xmlns:urn="urn:sap-com:document:sap:rfc:functions>
<soap:Body>
<urn:K23G_GET_COST_ELEMENTS>
<ID_BEKNZ xmlns="">S</ID_BEKNZ>
<ID_COLLECT_MESSAGES xmlns="">X</ID_COLLECT_MESSAGES>
<ID_GJAHR xmlns="">2016</ID_GJAHR>
<ID_KOKRS xmlns="">K001</ID_KOKRS>
<ID_VERSN xmlns="">000</ID_VERSN>
<ID_WRTTP xmlns="">04</ID_WRTTP>
<ET_MESG xmlns="">
<item />
</ET_MESG>
<ET_RESULTS xmlns="">
<item />
</ET_RESULTS>
<IT_COSEL_KSTAR xmlns="">
<item />
</IT_COSEL_KSTAR>
<IT_COSEL_OBJ xmlns="">
<item />
</IT_COSEL_OBJ>
</urn:K23G_GET_COST_ELEMENTS>
</soap:Body>
</soap:Envelope>
An this is how the request looks like:
The urn before K23G_GET_COST_ELEMENTS is missing
<?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:Body>
<K23G_GET_COST_ELEMENTS xmlns:urn="urn:sap-com:document:sap:rfc:functions>
<ID_BEKNZ xmlns="">S</ID_BEKNZ>
<ID_COLLECT_MESSAGES xmlns="">X</ID_COLLECT_MESSAGES>
<ID_GJAHR xmlns="">2016</ID_GJAHR>
<ID_KOKRS xmlns="">K001</ID_KOKRS>
<ID_VERSN xmlns="">000</ID_VERSN>
<ID_WRTTP xmlns="">04</ID_WRTTP>
<ET_MESG xmlns="">
<item />
</ET_MESG>
<ET_RESULTS xmlns="">
<item />
</ET_RESULTS>
<IT_COSEL_KSTAR xmlns="">
<item />
</IT_COSEL_KSTAR>
<IT_COSEL_OBJ xmlns="">
<item />
</IT_COSEL_OBJ>
</urn:K23G_GET_COST_ELEMENTS>
</soap:Body>
</soap:Envelope>
Somebody there who can help me?
Thank you

Fedex WSDL C# - Setting the Invoice # value

I'm using Fedex's WSDL in C# to generate COD shipping labels. On Fedex shipping labels there is an "Invoice #" string on both the shipping label and the COD return label. I want to set my orderid in the request to Fedex such that my orderid shows up as the Invoice #.
It's not obvious to me how to set the Invoice # in Fedex's wsdl request. Has anybody done this?
The way in which you place the order id or invoice number in the labels is following:
Set the invoice number in the package customer reference.
Specify on the COD details node (on the reference indicator) that you want the COD label to include the invoice number as one of its reference.
Please, note that you can also include other references than invoice number (e.g.: PO, customer reference, and tracking).
Here is a sample SOAP envelope for the request depicting what I said before:
<?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:Body>
<ProcessShipmentRequest xmlns="http://fedex.com/ws/ship/v12">
<WebAuthenticationDetail>
<CspCredential>
<Key>CSP_KEY(IF YOU ARE ONE)</Key>
<Password>CIS_PASSWORD(IF YOU ARE ONE)</Password>
</CspCredential>
<UserCredential>
<Key>CSP_USER_KEY(IF YOU BELONG TO THE CSP)</Key>
<Password>CSP_PASSWORD(IF YOU BELONG TO THE CSP)</Password>
</UserCredential>
</WebAuthenticationDetail>
<ClientDetail>
<AccountNumber>ACCOUNT_NUMBER</AccountNumber>
<MeterNumber>METER_NUMBER</MeterNumber>
<ClientProductId>CLIENT_PRODUCT_ID(IF ONE IS PROVIDED)</ClientProductId>
<ClientProductVersion>CLIENT_VERSION(IF ONE IS PROVIDED)</ClientProductVersion>
</ClientDetail>
<TransactionDetail>
<CustomerTransactionId>261</CustomerTransactionId>
</TransactionDetail>
<Version>
<ServiceId>ship</ServiceId>
<Major>12</Major>
<Intermediate>0</Intermediate>
<Minor>0</Minor>
</Version>
<RequestedShipment>
<ShipTimestamp>2013-08-21T14:00:00-04:00</ShipTimestamp>
<DropoffType>REGULAR_PICKUP</DropoffType>
<ServiceType>PRIORITY_OVERNIGHT</ServiceType>
<PackagingType>YOUR_PACKAGING</PackagingType>
<Shipper>
<AccountNumber>ACCOUNT_NUMBER</AccountNumber>
<Contact>
<PersonName>323199 323199</PersonName>
<CompanyName>CSP Testing</CompanyName>
<PhoneNumber>9012633035</PhoneNumber>
<EMailAddress>csp#fedex.com</EMailAddress>
</Contact>
<Address>
<StreetLines>99 Fedex parkway</StreetLines>
<City>ALAMEDA</City>
<StateOrProvinceCode>CA</StateOrProvinceCode>
<PostalCode>94501</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Shipper>
<Recipient>
<Contact>
<PersonName>323257 323257</PersonName>
<CompanyName>CSP Testing</CompanyName>
<PhoneNumber>9012633035</PhoneNumber>
<EMailAddress>csp#fedex.com</EMailAddress>
</Contact>
<Address>
<StreetLines>124 Fedex parkway</StreetLines>
<City>PADUCAH</City>
<StateOrProvinceCode>KY</StateOrProvinceCode>
<PostalCode>42001</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Recipient>
<Origin>
<Contact>
<PersonName>323199 323199</PersonName>
<CompanyName>CSP Testing</CompanyName>
<PhoneNumber>9012633035</PhoneNumber>
<EMailAddress>csp#fedex.com</EMailAddress>
</Contact>
<Address>
<StreetLines>99 Fedex parkway</StreetLines>
<City>ALAMEDA</City>
<StateOrProvinceCode>CA</StateOrProvinceCode>
<PostalCode>94501</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Origin>
<ShippingChargesPayment>
<PaymentType>SENDER</PaymentType>
<Payor>
<ResponsibleParty>
<AccountNumber>ACCOUNT_NUMBER</AccountNumber>
<Contact>
<PersonName>CSP Testing</PersonName>
<CompanyName>RTC Testing</CompanyName>
</Contact>
<Address>
<CountryCode>US</CountryCode>
</Address>
</ResponsibleParty>
</Payor>
</ShippingChargesPayment>
<SpecialServicesRequested>
<SpecialServiceTypes>COD</SpecialServiceTypes>
<CodDetail>
<CodCollectionAmount>
<Currency>USD</Currency>
<Amount>50</Amount>
</CodCollectionAmount>
<CollectionType>ANY</CollectionType>
<ReferenceIndicator>INVOICE</ReferenceIndicator>
</CodDetail>
</SpecialServicesRequested>
<CustomsClearanceDetail>
<DocumentContent>NON_DOCUMENTS</DocumentContent>
</CustomsClearanceDetail>
<LabelSpecification>
<LabelFormatType>COMMON2D</LabelFormatType>
<ImageType>PNG</ImageType>
<LabelStockType>PAPER_4X6</LabelStockType>
</LabelSpecification>
<RateRequestTypes>ACCOUNTACCOUNT</RateRequestTypes>
<PackageCount>1</PackageCount>
<RequestedPackageLineItems>
<SequenceNumber>1</SequenceNumber>
<GroupPackageCount>1</GroupPackageCount>
<InsuredValue>
<Currency>USD</Currency>
<Amount>5000</Amount>
</InsuredValue>
<Weight>
<Units>LB</Units>
<Value>20</Value>
</Weight>
<PhysicalPackaging>OTHER</PhysicalPackaging>
<ItemDescription>MacBook Pro</ItemDescription>
<CustomerReferences>
<CustomerReferenceType>INVOICE_NUMBER</CustomerReferenceType>
<Value>INVOICE12345</Value>
</CustomerReferences>
<SpecialServicesRequested>
<SpecialServiceTypes>SIGNATURE_OPTION</SpecialServiceTypes>
<SignatureOptionDetail>
<OptionType>SERVICE_DEFAULT</OptionType>
</SignatureOptionDetail>
</SpecialServicesRequested>
</RequestedPackageLineItems>
</RequestedShipment>
</ProcessShipmentRequest>
</soap:Body>
</soap:Envelope>
This is the generated shipping label:
This is the generated COD label:
I hope my reply is of help to you.
Best!

soap service The specified type was not recognized

Can anyone tell me why I get:
{"The specified type was not recognized: name='anyType', namespace='http://www.mywebsite.com/webservice/service.wsdl', at <response xmlns=''>."}
And the xml that I'm getting is:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mywebsite.com/webservice/service.wsdl" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:getCarsResponse>
<response SOAP-ENC:arrayType="ns1:anyType[2]" xsi:type="ns1:carlist">
<item xsi:type="SOAP-ENC:Struct">
<id xsi:type="xsd:string">1392</id>
<merk xsi:type="xsd:string">Citroen</merk>
<type xsi:type="xsd:string">C1</type>
<uitvoering xsi:type="xsd:string">1.0i Selection 5D</uitvoering>
<leaseprijs xsi:type="xsd:string">299,--</leaseprijs>
<looptijd xsi:type="xsd:string">18</looptijd>
<kilometrage xsi:type="xsd:string">25.000</kilometrage>
<thumbnail xsi:type="xsd:string">/i_upload/free/_th.gif</thumbnail>
</item>
<item xsi:type="SOAP-ENC:Struct">
<id xsi:type="xsd:string">1393</id>
<merk xsi:type="xsd:string">Citroen</merk>
<type xsi:type="xsd:string">C1</type>
<uitvoering xsi:type="xsd:string">1.0i Selection 5D</uitvoering>
<leaseprijs xsi:type="xsd:string">299,--</leaseprijs>
<looptijd xsi:type="xsd:string">18</looptijd>
<kilometrage xsi:type="xsd:string">25.000</kilometrage>
<thumbnail xsi:type="xsd:string">/i_upload/free/_th.gif</thumbnail>
</item>
</response>
</SOAP-ENV:getCarsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I invoke the SOAP service in this way:
Service.service_portClient proxy = new Service.service_portClient();
proxy.getCars("Citroen", benzine);

Creating Maintainable Xml structure for a relational database

I am not trying to save dataset or datatable to a xml file rather create a xml structure for saving related data? For example i would like to know how below data could be in a xml file
User
UserId
Username
Password
Roles
RoleId
UserId [FK]
CreatedOn
will it look like this
<User userid="" username="" password="">
<Roles id="">
<Name></Name>
<Description></Description>
</Roles>
</User>
which structure would be best to use xml files as DB
I think you want to consider implementing the XML in a more normalized manner, similar to how you would do so with a relational database. For instance in your current solution you would be required to type out the entire role structure within every user such as
<User userid="1" username="user01" password="password">
<Roles id="1">
<Name>Role 1</Name>
<Description>This is Role 1</Description>
</Roles>
</User>
<User userid="2" username="user02" password="password">
<Roles id="1">
<Name>Role 1</Name>
<Description>This is Role 1</Description>
</Roles>
</User>
A normalized structure could look like the following
<Roles>
<Role id="1">
<Name>Role 1</Name>
<Description>This is Role 1</Description>
</Role>
</Roles>
<User id="1" username="user01" password="password">
<Roles>
<Role>1</Role>
</Roles>
</User>
<User id="2" username="user02" password="password">
<Roles>
<Role>1</Role>
</Roles>
</User>
Hope this helps

Categories

Resources