ThyRock,
I have it working....let me know if you need help with the code....
email me
precept33@hotmail.com
Precept
Precept wrote:[color=blue]
> ThyRock,
>
> I have the xml version just about done I am authenticating and get a
> response but its saying I don't have a well formed document..funny i[/color]
am[color=blue]
> using the example they provided...I should have it figured out by
> tonight
>
> Precept
>
> Precept wrote:[color=green]
> > ThyRock,
> >
> > Sorry to get back to you so late...was at work late and just[/color][/color]
finished[color=blue][color=green]
> > with the family thing dinner etc.....
> > I used the HTML developers guide because it was easy to[/color]
> develop....here[color=green]
> > is the code along with my USPS code
> > I am using webservices for all three DHL, UPS, and USPS...damn[/color][/color]
fedex[color=blue][color=green]
> > can't get there stinkin docs! I changed my USPS code to a[/color]
> stringbuilder[color=green]
> > like your example..code looks a little more cluttered using
> > XmlTextWriter, MemoryStream, and XmlDocument...
> > I have some merchant components coded, we can exhange some code if[/color]
> you[color=green]
> > would like...The ups xml service is pretty straight forward maybe I
> > will code for the xml service this weekend, if you want to wait[/color][/color]
till[color=blue][color=green]
> > then..otherwise this one works
> >
> > Cheers,
> >
> > Precept
> >
> > -----UPS
> > [WebMethod]
> > public decimal GetPrice(string svcCode, string rateChart,string
> > shipperZIP,string receiverZIP,
> > string receiverCountry,string[/color][/color]
pkgWeight,string[color=blue][color=green]
> > isResidential, string isCOD,
> > string isSatPickup,string isSatDelivery, string pkgType)
> > {
> > decimal shippingRate = 0;
> > WebRequest myWebReq;
> > WebResponse myWebResp;
> > StreamReader myStream;
> > string URLRequest;
> > string responseLine;
> >
> > URLRequest =
> >[/color]
>[/color]
BuildRequest(svcCode,rateChart,shipperZIP,receiver ZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup ,isSatDelivery,pkgType);[color=blue][color=green]
> >
> >
> > myWebReq = WebRequest.Create(URLRequest);
> > myWebResp = myWebReq.GetResponse();
> >
> > myStream = new StreamReader(myWebResp.GetResponseStream(),
> > System.Text.Encoding.ASCII);
> > try
> > {
> > responseLine = myStream.ReadLine();
> >
> > while(responseLine != null)
> > {
> > responseLine = myStream.ReadLine();
> >
> > if (responseLine.Length > 0)
> > {
> > if (responseLine.ToLower().IndexOf("upsonline", 0,
> > responseLine.Length) > -1)
> > {
> > string[] arr;
> > char[] perct = new char[1];
> > perct[0] = '%';
> > arr = responseLine.Split(perct);
> > if (arr[3].Substring(0,11).ToLower() == "0000success")
> > shippingRate = Convert.ToDecimal(arr[12]);
> >
> > responseLine = null;
> > }
> > }
> >
> > }
> >
> >
> > }
> > catch(Exception e)
> > {
> > throw new AppException("Error occured trying to calculate UPS
> > shiping", e);
> > }
> >
> > return shippingRate;
> > }
> >
> >
> > private string BuildRequest(string svcCode, string rateChart,[/color][/color]
string[color=blue][color=green]
> > shipperZIP, string receiverZIP,
> > string receiverCountry, string pkgWeight, string isResidential,
> > string isCOD,
> > string isSatPickup, string isSatDelivery, string pkgType)
> > {
> >
> > System.Text.StringBuilder ups = new System.Text.StringBuilder();
> >
> >[/color]
>[/color]
ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");[color=blue][color=green]
> > ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreeme nt=YES&");
> > ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
> > ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" +[/color]
> rateChart[color=green]
> > + "&");
> > ups.Append("ShipperPostalCode=" + shipperZIP +
> > "&ConsigneePostalCode=" + receiverZIP + "&");
> > ups.Append("ConsigneeCountry=" + receiverCountry +
> > "&PackageActualWeight=" + pkgWeight + "&");
> > ups.Append("ResidentialInd=" + isResidential + "&CODInd=" +[/color][/color]
isCOD[color=blue]
> +[color=green]
> > "&SatDelivInd=" + isSatDelivery);
> > ups.Append("&SatPickupInd=" + isSatPickup + "&PackagingType=" +
> > pkgType);
> >
> > return
> > ups.ToString();
> > }
> >
> >
> > ----USPS
> > [WebMethod]
> > public decimal GetPrice(string userID, string password, string
> > zipOrigin, string zipDestination,
> > string pounds, string ounces, string container, string size,[/color]
> string[color=green]
> > service)
> > {
> > WebRequest myWebReq;
> > WebResponse myWebResp;
> > StreamReader myStream;
> > string UrlRequest;
> > decimal shippingRate = 0;
> >
> > UrlRequest = BuildRequest(userID, password, zipOrigin,
> > zipDestination, pounds, ounces, container, size, service);
> >
> > myWebReq = WebRequest.Create(UrlRequest);
> >
> > try
> > {
> > myWebResp = myWebReq.GetResponse();
> >
> > myStream = new StreamReader(myWebResp.GetResponseStream(),
> > System.Text.Encoding.ASCII);
> >
> > XmlTextReader xmlReader = new XmlTextReader(myStream);
> >
> > System.Text.StringBuilder response = new
> > System.Text.StringBuilder();
> >
> > while (xmlReader.Read())
> > {
> > if (xmlReader.MoveToContent() == XmlNodeType.Element &&
> > xmlReader.Name.ToUpper() == "RATE")
> > {
> > shippingRate = Convert.ToDecimal(xmlReader.ReadString());
> > }
> > }
> >
> > return shippingRate;
> > }
> > catch(Exception e)
> > {
> > throw new AppException("Error occured trying to calculate USPS
> > shiping", e);
> > }
> > }
> >
> > private string BuildRequest(string userID, string password,[/color][/color]
string[color=blue][color=green]
> > zipOrigin,
> > string zipDestination, string pounds, string ounces, string
> > container,
> > string size, string service)
> > {
> > System.Text.StringBuilder usps = new[/color][/color]
System.Text.StringBuilder();[color=blue][color=green]
> >[/color]
>[/color]
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");[color=blue][color=green]
> > usps.Append( "?API=RateV2&XML=" );
> > usps.Append( "<RateV2Request USERID=\"" );
> > usps.Append( userID + "\" " );
> > usps.Append( "PASSWORD=\"" );
> > usps.Append( password + "\">" );
> > usps.Append( "<Package ID=\"0\">" );
> > usps.Append( "<Service>" + service + "</Service>" );
> > usps.Append( "<ZipOrigination>" + zipOrigin +[/color][/color]
"</ZipOrigination>"[color=blue]
> );[color=green]
> >
> > usps.Append( "<ZipDestination>" + zipDestination +
> > "</ZipDestination>" );
> > usps.Append( "<Pounds>" + pounds + "</Pounds>" );
> > usps.Append( "<Ounces>" + ounces + "</Ounces>" );
> > usps.Append( "<Container>" + container + "</Container>" );
> > usps.Append( "<Size>" + size + "</Size>" );
> > usps.Append( "</Package></RateV2Request>" );
> >
> > return usps.ToString();
> > }
> >
> > ThyRock wrote:[color=darkred]
> > > Precept,
> > > I tried the URI object and it will return a uri without encoding[/color][/color][/color]
if[color=blue][color=green]
> > you pass[color=darkred]
> > > the dontencode parameter set to true.
> > > I tried the StringBuilder approach and it worked so I have move[/color][/color][/color]
on[color=blue]
> to[color=green]
> > the[color=darkred]
> > > next step.
> > > There are many ways of reaching the same end and I would like[/color][/color][/color]
very[color=blue][color=green]
> > much to[color=darkred]
> > > look at
> > > your approach to using the UPS DHL services.
> > > Thanks,
> > >
> > > "Precept" wrote:
> > >
> > > > ThyRock,
> > > >
> > > > Thx for the quick response. I see that you are not using as Uri[/color]
> > object[color=darkred]
> > > > and are passing in a StringBuilder...hmm I will have to try[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > > hopefully the XML format will be maintained and not encoded. I[/color][/color]
> have[color=green]
> > the[color=darkred]
> > > > UPS shipping code done. I don't know if you want to build the[/color]
> > component[color=darkred]
> > > > yourself for the experience or whatever..., but I have the code[/color][/color]
> and[color=green]
> > can[color=darkred]
> > > > give it to you if you want to save coding time. BTW I also have[/color][/color]
> the[color=green]
> > DHL[color=darkred]
> > > > component done if you want that one too, or I can give you the[/color][/color]
> info[color=green]
> > you[color=darkred]
> > > > need if you want to code that component yourself..just let me[/color][/color]
> know[color=green][color=darkred]
> > > >
> > > > Thx Precept
> > > >
> > > >
> > > > ThyRock wrote:
> > > > > Precept,
> > > > > I am also working on a Shipping component, and would be[/color]
> > interested in[color=darkred]
> > > > any
> > > > > problems I may encounter on the UPS service. I have got the[/color][/color]
> USPS[color=green][color=darkred]
> > > > service
> > > > > working and am now going to start on the UPS service. I have
> > > > included the
> > > > > USPS code for you.
> > > > >
> > > > > replace userid with your USPS UserID
> > > > > replace userpassword with your USPS Password
> > > > >
> > > > > string userID = "userid";
> > > > > string password = "userpassword";
> > > > > string service = "PRIORITY";
> > > > > string zipOrigination = "10022";
> > > > > string zipDestination = "20008";
> > > > > string pounds = "10";
> > > > > string ounces = "5";
> > > > > string container = "Flat Rate Box";
> > > > > string size = "REGULAR";
> > > > >
> > > > > StringBuilder stringBuilder = new StringBuilder(
> > > > > "http://testing.shippingapis.com/ShippingAPITest.dll" );
> > > > >
> > > > > stringBuilder.Append( "?API=RateV2&XML=" );
> > > > > stringBuilder.Append( "<RateV2Request USERID=\"" );
> > > > > stringBuilder.Append( userID + "\" " );
> > > > > stringBuilder.Append( "PASSWORD=\"" );
> > > > > stringBuilder.Append( password + "\">" );
> > > > > stringBuilder.Append( "<Package ID=\"0\">" );
> > > > > stringBuilder.Append( "<Service>" + service + "</Service>" );
> > > > > stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
> > > > > "</ZipOrigination>" );
> > > > > stringBuilder.Append( "<ZipDestination>" + zipDestination +
> > > > > "</ZipDestination>" );
> > > > > stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
> > > > > stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
> > > > > stringBuilder.Append( "<Container>" + container +[/color][/color]
> "</Container>"[color=green]
> > );[color=darkred]
> > > > > stringBuilder.Append( "<Size>" + size + "</Size>" );
> > > > > stringBuilder.Append( "</Package></RateV2Request>" );
> > > > >
> > > > > WebRequest webRequest = WebRequest.Create([/color]
> > stringBuilder.ToString()[color=darkred]
> > > > );
> > > > >
> > > > > try
> > > > > {
> > > > > WebResponse webResponse = webRequest.GetResponse();
> > > > > Stream webResponseStream = webResponse.GetResponseStream();
> > > > >
> > > > > // txtHTML is a TextArea control to display the raw[/color][/color][/color]
response[color=blue][color=green]
> > for[color=darkred]
> > > > > development
> > > > > // purposes.
> > > > > // You would unpack the xml document here and return the[/color][/color]
> needed[color=green][color=darkred]
> > > > values
> > > > >
> > > > > Byte[] read = new Byte[512];
> > > > > int bytes = webResponseStream.Read( read, 0, 512 );
> > > > >
> > > > > txtHTML.InnerHtml = "";
> > > > > while ( bytes > 0 )
> > > > > {
> > > > > // Note:
> > > > > // The following assumes that the response uses UTF-8 as[/color]
> > encoding.[color=darkred]
> > > > > // If the content is sent in a ANSI codepage like 932 use
> > > > something like
> > > > > this:
> > > > > // Encoding encode =
> > > > System.Text.Encoding.GetEncoding("shift-jis");
> > > > > Encoding encode = System.Text.Encoding.GetEncoding([/color][/color][/color]
"utf-8"[color=blue]
> );[color=green][color=darkred]
> > > > > txtHTML.InnerHtml = txtHTML.InnerHtml +[/color][/color]
> encode.GetString(read,[color=green]
> > 0,[color=darkred]
> > > > bytes);
> > > > > bytes = webResponseStream.Read( read, 0, 512 );
> > > > >
> > > > > // End of development code.
> > > > > }
> > > > > }
> > > > > catch(Exception)
> > > > > {
> > > > > txtHTML.InnerHtml = "Error retrieving page";
> > > > > }
> > > > >
> > > > > The above request returns the following response:
> > > > >
> > > > > <?xml version="1.0"?>
> > > > > <RateV2Response><Package
> > > > >
> > > >[/color]
> >[/color]
>[/color]
ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat[color=blue][color=green][color=darkred]
> > > >
> > > > > Rate
> > > > >
> > > >[/color]
> >[/color]
>[/color]
Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority[color=blue][color=green][color=darkred]
> > > >
> > > > > Mail Flat Rate Box (11.25" x 8.75" x
> > > > >
> > > >[/color]
> >[/color]
>[/color]
6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority[color=blue][color=green][color=darkred]
> > > >
> > > > > Mail Flat Rate Box (14" x 12" x
> > > > >
> > > >[/color]
> >[/color]
>[/color]
3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=blue][color=green][color=darkred]
> > > > >
> > > > > "Precept" wrote:
> > > > >
> > > > > > ThyRock,
> > > > > >
> > > > > > I have been working on trying to pass the userid and[/color][/color][/color]
password[color=blue][color=green][color=darkred]
> > > > without
> > > > > > the escape character for a solid week. I came across this[/color]
> > article[color=darkred]
> > > > and
> > > > > > saw that you encountered the same problem. How did you fix[/color][/color]
> it?[color=green]
> > I[color=darkred]
> > > > > > currently use an XmlTextWriter, Memory Stream and[/color][/color][/color]
XmlDocument[color=blue][color=green][color=darkred]
> > > > objects
> > > > > > to form the xml parameter. I am trying to complete an[/color][/color]
> ecommerce[color=green][color=darkred]
> > > > site
> > > > > > for a friends business. He uses dhl, ups, and usps for his
> > > > shipping. I
> > > > > > have 2 of 3 done, but the usps is becoming pesky problem.[/color][/color][/color]
Do[color=blue][color=green]
> > you[color=darkred]
> > > > have
> > > > > > any suggestions? Any help would be appreciated
> > > > > >
> > > > > > Precept
> > > > > >
> > > > > > ThyRock wrote:
> > > > > > > Bruce,
> > > > > > > Again, thanks very much for your help, I have work out[/color][/color][/color]
this[color=blue][color=green][color=darkred]
> > > > problem.
> > > > > > >
> > > > > > >
> > > > > > > "ThyRock" wrote:
> > > > > > >
> > > > > > > > I am working on a WebRequest accessing the US Postal[/color]
> > Service[color=darkred]
> > > > > > WebTools test API.
> > > > > > > > This service uses a DLL file (ShippingAPITest.dll) with[/color][/color][/color]
a[color=blue][color=green]
> > query[color=darkred]
> > > > > > string which
> > > > > > > > includes XML.
> > > > > > > > The web service accepts the query string with no url[/color]
> > encoding.[color=darkred]
> > > > > > > > I must pass the <> characters as they are in the query[/color]
> > string.[color=darkred]
> > > > > > > > If these characters are url encoded the service rejects[/color][/color]
> the[color=green][color=darkred]
> > > > > > request.
> > > > > > > >
> > > > > > > >
> > > > > > > > This API Url is
> > > > > > > >
http://testing.shippingapis.com/ShippingAPITest.dll
> > > > > > > >
> > > > > > > > It takes a query string as follows:
> > > > > > > >
> > > > > > > > ?API=RateV2&XML=<RateV2Request USERID="userid"
> > > > PASSWORD="password">
> > > > > > <Package
> > > > > > > > ID="0"> <Service>PRIORITY</Service>
> > > > > > <ZipOrigination>10022</ZipOrigination>
> > > > > > > > <ZipDestination>20008</ZipDestination>[/color][/color]
> <Pounds>10</Pounds>[color=green][color=darkred]
> > > > > > <Ounces>5</Ounces>
> > > > > > > > <Container>Flat Rate Box</Container>
> > > > > > > > <Size>REGULAR</Size></Package></RateV2Request>
> > > > > > > >
> > > > > > > >
> > > > > > > > I can use this url and query string from the location[/color][/color][/color]
bar[color=blue][color=green]
> > of[color=darkred]
> > > > the
> > > > > > web
> > > > > > > > browser and it will return the correct xml response.[/color][/color][/color]
If[color=blue][color=green]
> > this[color=darkred]
> > > > query
> > > > > > string is
> > > > > > > > encoded, the DLL will return an error. The USPS DLL is[/color][/color]
> not[color=green][color=darkred]
> > > > > > decoding an
> > > > > > > > encoded query string. The USPS is not up to date with[/color][/color]
> the[color=green][color=darkred]
> > > > latest
> > > > > > Xml
> > > > > > > > technology and uses the DLL to retreive the query[/color][/color][/color]
string[color=blue][color=green]
> > and[color=darkred]
> > > > > > process the
> > > > > > > > request.
> > > > > > > > I am very limited to what I can do with this service[/color]
> > provider.[color=darkred]
> > > > > > > >
> > > > > > > > Can someone tell me how to use the WebRequest method[/color]
> > without[color=darkred]
> > > > > > encoding the
> > > > > > > > request?
> > > > > > > >
> > > > > > > > Thanks for your help.
> > > > > >
> > > > > >
> > > >
> > > >[/color][/color][/color]