Jump to content

XML ASP SOAP


khadem1386

Recommended Posts

Hi I want use XML for contact to the compay like Fedex.1-send Rate request.2-and get reply. with XMLI want use SOAP method but I am new in XML And SAOP.I work with ASP3 no .NetCan I use SOPA in asp for commincatins between us and commpanies?Thank for lead

Link to comment
Share on other sites

I have worked with fedex's process before and found that it is easiest to just use an xmlHTTP request using xml DOM. Below is a sample of what I used to complete this request. Hope this helps.

set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")URL = "[b]the url to the fedex gateway[/b]"oXMLHTTP.Open "POST",URL,"false"oXMLHTTP.SetRequestHeader "Referer"oXMLHTTP.setRequestHeader "Host", "[b]fedex gateway[/b]"oXMLHTTP.setRequestHeader "Accept", "image/jpeg,image/pjpeg, text/plain, text/html, */*"oXMLHTTP.setRequestHeader "Content-Type", "text/xml"oXMLHTTP.setRequestHeader "Content-Length", cStr(len(TS))oXMLHTTP.send(TS)'TS = ""'response.Write(oXMLHTTP.responseText)'Send the response from the FedEx Server to be processedset responseXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")ProcessingURL = "[b]a page you create to process the xml[/b]"responseData = oXMLHTTP.responseTextresponseXMLHTTP.Open "POST", ProcessingURL ,"false"responseXMLHTTP.setRequestHeader "Content-Type", "text/xml"responseXMLHTTP.send(responseData)

Link to comment
Share on other sites

I am very glad that I find you. :) could you genrate for example:Meter number?or send a rate request (XML)and get repaly of Fedex (XML).I want work with your codebut how we can fill TS and then send TS?I think that we must fill TS with an XML. it is trueI am new in XMLbut it have very simple format.I make an XML subscrib and now I don't know how can I transfom it to TS. (for examples)Can you help me for clear this code.I see like this code in Fedx manuals. (in direct methode)thank for your help.

Link to comment
Share on other sites

The meter number has to be obtained from a fedex rep. As well as the gateway and url to the fedex server.Below is how you build the xml string. Just fill in the correct data needed for the xml that goes with the type of transaction you are working with. You can find the xml in one of the FedEx documents on there site.

TS = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _"<FDXEmailLabelRequest xmlns:api=""http://www.fedex.com/fsmapi"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:noNamespaceSchemaLocation=""FDXEmailLabelRequest.xsd"">" & _"<RequestHeader>" & _"<CustomerTransactionIdentifier>Email Label Request</CustomerTransactionIdentifier>" & _"<AccountNumber>" & AccountNumber & "</AccountNumber>" & _"<MeterNumber>" & MeterNumber & "</MeterNumber>" & _"<CarrierCode>" & CarrierCode & "</CarrierCode>" & _"</RequestHeader>" &_ "<URLExpirationDate>" & URLExpirationDate & "</URLExpirationDate>" & _"<URLNotificationE-MailAddress>" & OriginEmail & "</URLNotificationE-MailAddress>" & _"<MerchantPhoneNumber>" & MerchantPhoneNumber & "</MerchantPhoneNumber>" & _"<Service>" & Service & "</Service>" & _"<Packaging>" & Packaging & "</Packaging>" & _"<WeightUnits>" & WeightUnits & "</WeightUnits>" & _"<CurrencyCode>" & CurrencyCode & "</CurrencyCode>" & _"<Origin>" & _"<Contact>" & _"<PersonName>" & OriginPersonName & "</PersonName>" & _CompName & _"<PhoneNumber>" & OriginPhoneNumber & "</PhoneNumber>" & _"<E-MailAddress>" & OriginEmail & "</E-MailAddress>" & _"</Contact>" & _"<Address>" & _"<Line1>" & OriginAddress1 & "</Line1>" & _Address2 & _"<City>" & OriginCity & "</City>" & _"<StateOrProvinceCode>"& OriginState &"</StateOrProvinceCode>" & _"<PostalCode>" & OriginZip & "</PostalCode>" & _"<CountryCode>"& OriginCountryCode &"</CountryCode>" & _"</Address>" & _"</Origin>" & _"<Destination>" & _"<Contact>" & _"<PersonName>" & DestinationPersonName & "</PersonName>" & _"<CompanyName>" & DestinationCompanyName & "</CompanyName>" & _"<PhoneNumber>" & DestinationPhoneNumber & "</PhoneNumber>" & _"</Contact>" & _"<Address>" & _"<Line1>" & DestinationAddress1 & "</Line1>" & _"<Line2>" & DestinationAddress2 & "</Line2>" & _"<City>" &  DestinationCity & "</City>" & _"<StateOrProvinceCode>" & DestinationState & "</StateOrProvinceCode>" & _"<PostalCode>" & DestinationZip & "</PostalCode>" & _"<CountryCode>" & DestinationCountryCode & "</CountryCode>" & _"</Address>" & _"</Destination>" & _"<Payment>" & _"<PayorType>SENDER</PayorType>" & _"<Payor>" & _"<AccountNumber></AccountNumber>" & _"</Payor>" & _"</Payment>" & _"<DimensionsUnits>IN</DimensionsUnits>" & _"<Package>" & _"<Weight>1.0</Weight>" & _"<DeclaredValue>100.00</DeclaredValue>" & _"<ItemDescription>Books</ItemDescription>" & _"</Package>	" & _"</FDXEmailLabelRequest>"

Then the code below will send it to the fedex server, recieve a response back from the server and then send it to a page to process the xml and then send it back to display from the middle page.

------------THIS CODE SENDS THE STRING FROM ABOVE----------------set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")URL = "[b]the url to the fedex gateway[/b]"oXMLHTTP.Open "POST",URL,"false"oXMLHTTP.SetRequestHeader "Referer"oXMLHTTP.setRequestHeader "Host", "[b]fedex gateway[/b]"oXMLHTTP.setRequestHeader "Accept", "image/jpeg,image/pjpeg, text/plain, text/html, */*"oXMLHTTP.setRequestHeader "Content-Type", "text/xml"oXMLHTTP.setRequestHeader "Content-Length", cStr(len(TS))oXMLHTTP.send(TS)set responseXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")ProcessingURL = "[b]a page you create to process the xml[/b]"responseData = oXMLHTTP.responseTextresponseXMLHTTP.Open "POST", ProcessingURL ,"false"responseXMLHTTP.setRequestHeader "Content-Type", "text/xml"responseXMLHTTP.send(responseData)

This code below is the page that you will send the xml data to to process it. It isn't exactly what you will need but might give you a clue. Insert the url for this page in the ProcessingURL in the code above.

Set xmlDoc = CreateObject("MSXML2.DOMDocument")xmlDoc.async = falsexmlDoc.setProperty "ServerHTTPRequest", TruexmlDoc.load(request)set theLength = xmlDoc.getElementsByTagName("ReplyHeader")Set TransIden = xmlDoc.getElementsByTagName("CustomerTransactionIdentifier")if xmlDoc.getElementsByTagName("CustomerTransactionIdentifier").length = 0 thenfor each x in xmldoc.documentElement.childNodes	response.Write(x.text)	nextfor i = 0 to theLength.length - 1Response.Write("Label: ")Response.Write(TransIden(0).text & "<br />" & vbCrLf)nextfor each x in xmldoc.documentElement.childNodes   if x.NodeName = "URL" then URL=x.textnextResponse.Write("URL: ")response.write "<a href=""" & URL & """>" & URL & "</a>"response.write("<br>")for each x in xmldoc.documentElement.childNodes   if x.NodeName = "RequestTimestamp" then TimeStamp=x.textnextResponse.Write("Time Stamp: ")response.write(TimeStamp)response.write("<br>")for each x in xmldoc.documentElement.childNodes   if x.NodeName = "UserID" then ID=x.textnextResponse.Write("User ID: ")response.write(ID)response.write("<br>")for each x in xmldoc.documentElement.childNodes   if x.NodeName = "Password" then Password=x.textnextResponse.Write("Password: ")response.write(Password)response.write("<br>")set PackageLength = xmlDoc.getElementsByTagName("Package")Set TrackNumber = xmlDoc.getElementsByTagName("TrackingNumber")for x = 0 to PackageLength.length - 1Response.Write("Tracking Number: ")Response.Write(TrackNumber(x).text & "<br />" & vbCrLf)next

I hope this helps, I know this is kind of confusing.

Link to comment
Share on other sites

Thanks for your code and your time.It is very helpfull for me and know I near my mind 1 step.I send TS (XML) successfuly. (by help you) and konw get DATA by variables.( and no by XML)the Fedex offer this code: (as you know)

ResultBytes = oXMLHTTP.responseBody 'Convert the ByteArray data to a String for index = LBound( ResultBytes) To UBound( ResultBytes ) + 1 ResultString = ResultString & Chr(AscB(MidB( ResultBytes, index, 1 ))) Next

I think this code in above generate reply to a readable string.but it don't work goodbut may index not full correctly and MidB return error:Microsoft VBScript runtime error '800a0005' Invalid procedure call or argument: 'Midb' /sendHTTP2.asp, line 33 this is my full code:

<%TS= "<?xml version=""1.0"" encoding=""UTF-8"" ?><FDXRateAvailableServicesRequest xmlns:api=""http://www.fedex.com/fsmapi"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:noNamespaceSchemaLocation=""FDXRateAvailableServicesRequest.xsd""><RequestHeader><CustomerTransactionIdentifier>Express Rate Services</CustomerTransactionIdentifier><AccountNumber>888888888</AccountNumber><MeterNumber>12121212</MeterNumber><CarrierCode></CarrierCode></RequestHeader><ShipDate>2007-05-29</ShipDate><DropoffType>REGULARPICKUP</DropoffType><Packaging>YOURPACKAGING</Packaging><WeightUnits>LBS</WeightUnits><Weight>75.0</Weight><OriginAddress><StateOrProvinceCode>OH</StateOrProvinceCode><PostalCode>44333</PostalCode><CountryCode>US</CountryCode></OriginAddress><DestinationAddress><StateOrProvinceCode>CA</StateOrProvinceCode><PostalCode>90211</PostalCode><CountryCode>US</CountryCode></DestinationAddress><Payment><PayorType>SENDER</PayorType></Payment></FDXRateAvailableServicesRequest>"  set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")URL = "https://gatewaybeta.fedex.com:443/GatewayDC"oXMLHTTP.Open "POST",URL,"false"oXMLHTTP.SetRequestHeader "Referer","PANASYSTEM"oXMLHTTP.setRequestHeader "Host", "https://gatewaybeta.fedex.com:443/GatewayDC"oXMLHTTP.setRequestHeader "Accept", "image/jpeg,image/pjpeg, text/plain, text/html, */*"oXMLHTTP.setRequestHeader "Content-Type", "text/xml"oXMLHTTP.setRequestHeader "Content-Length", cStr(len(TS))oXMLHTTP.send(TS)responseData = oXMLHTTP.responseTextResponse.Write (responseData)%><BR><BR><BR><BR><BR><BR><BR><%ResultBytes = oXMLHTTP.responseBody Response.Write (Resultbytes)'Convert the ByteArray data to a String for index = LBound( ResultBytes) To UBound( ResultBytes ) + 1 Response.Write (index)ResultString = ResultString & Chr(AscB(Midb( ResultBytes, index, 1 ))) Next  Response.Write (ResultString) %>

and I recieve only ???????????? instead Response.Write (Resultbytes)This is address for this code:Visit My page(http://www.panasystem.com/sendHTTP2.asp)Do you work with Lbound and Ubound Mothed in this project?Thank for your time

Link to comment
Share on other sites

I'm not following this conversation, but for the

and I recieve only ???????????? instead Response.Write (Resultbytes)
issue, you can get that with mixed up encodings. Verify that all envolved documents are served with one encoding (UTF-8 in this case I see), and that this same encoding is used with transmission to both sides. You should set the send and rensponse HTTP headers with something like
oXMLHTTP.setRequestHeader "Content-Type", "text/xml;charset=utf-8"

to do so.

Link to comment
Share on other sites

oXMLHTTP.setRequestHeader "Content-Type", "text/xml;charset=utf-8"

to do so.

Hino, I use UTF-8 and it don't cheged any thing.here we have 2 kind of issue Command. as you see:1.responseData = oXMLHTTP.responseTextResponse.Write (responseData)2.ResultBytes = oXMLHTTP.responseBody Response.Write (Resultbytes)What is differ of them?I want get lik this (replay) in belowin issue. I can be in XML or some variable in asp.and I think variable in better.
The following is an example of the FDXRateReply:<?xml version="1.0" encoding="UTF-8" ?><FDXRateReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ReplyHeader><CustomerTransactionIdentifier>CTIString</CustomerTransactionIdentifier></ReplyHeader><EstimatedCharges><DimWeightUsed>false</DimWeightUsed><RateScale>01552</RateScale><RateZone>5</RateZone><CurrencyCode>USD</CurrencyCode><BilledWeight>10.0</BilledWeight><DiscountedCharges><BaseCharge>47.75</BaseCharge><TotalDiscount>0.00</TotalDiscount><Surcharges><Fuel>2.63</Fuel><Other>0.00</Other></Surcharges><TotalSurcharge>2.63</TotalSurcharge><NetCharge>50.38</NetCharge><TotalRebate>0.00</TotalRebate></DiscountedCharges><ListCharges><Surcharges><Fuel>2.63</Fuel><Other>0.00</Other></Surcharges></ListCharges></EstimatedCharges></FDXRateReply>

we must generate issue to some varable. (I think)Thank for your attions

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...