首页 新闻 搜索 专区 学院

联邦快递dEMO 运行问题

0
悬赏园豆:10 [待解决问题]

     

// This code was built using Visual Studio 2005
using System;
using TrackWebServiceClient.TrackServiceWebReference;
using System.Web.Services.Protocols;

// Sample code to call the FedEx Track Web Service
// Tested with Microsoft Visual Studio 2005 Professional Edition
namespace TrackWebServiceClient
{
class Program
{
static void Main(string[] args)
{
TrackRequest request = CreateTrackRequest();
//
TrackService service = new TrackService();
if (usePropertyFile())
{
service.Url = getProperty("endpoint");
}
//
try
{
// Call the Track web service passing in a TrackRequest and returning a TrackReply
TrackReply reply = service.track(request);
if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
{
ShowTrackReply(reply);
}
ShowNotifications(reply);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerText);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Press any key to quit!");
Console.ReadKey();
}

private static TrackRequest CreateTrackRequest()
{
// Build the TrackRequest
TrackRequest request = new TrackRequest();
//
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
request.WebAuthenticationDetail.UserCredential.Key = "XXX"; // Replace "XXX" with the Key
request.WebAuthenticationDetail.UserCredential.Password = "XXX"; // Replace "XXX" with the Password
if (usePropertyFile()) //Set values from a file for testing purposes
{
request.WebAuthenticationDetail.UserCredential.Key = getProperty("key");
request.WebAuthenticationDetail.UserCredential.Password = getProperty("password");
}
//
request.ClientDetail = new ClientDetail();
request.ClientDetail.AccountNumber = "XXX"; // Replace "XXX" with the client's account number
request.ClientDetail.MeterNumber = "XXX"; // Replace "XXX" with the client's meter number
if (usePropertyFile()) //Set values from a file for testing purposes
{
request.ClientDetail.AccountNumber = getProperty("accountnumber");
request.ClientDetail.MeterNumber = getProperty("meternumber");
}
//
request.TransactionDetail = new TransactionDetail();
request.TransactionDetail.CustomerTransactionId = "***Track By Reference Request using VC#***"; //This is a reference field for the customer. Any value can be used and will be provided in the response.
//
request.Version = new VersionId();
//
// Tracking information
request.SelectionDetails = new TrackSelectionDetail[1] { new TrackSelectionDetail() };
request.SelectionDetails[0].PackageIdentifier = new TrackPackageIdentifier();
request.SelectionDetails[0].PackageIdentifier.Value = "XXX"; // Replace "XXX" with tracking number or door tag
if (usePropertyFile()) //Set values from a file for testing purposes
{
request.SelectionDetails[0].PackageIdentifier.Value = getProperty("reference");
}
request.SelectionDetails[0].PackageIdentifier.Type = TrackIdentifierType.CUSTOMER_REFERENCE;
//
request.SelectionDetails[0].ShipmentAccountNumber = "XXX";
if (usePropertyFile()) //Set values from a file for testing purposes
{
request.SelectionDetails[0].ShipmentAccountNumber = getProperty("shipaccount");
}
// Date range is optional.
// If omitted, set to false
request.SelectionDetails[0].ShipDateRangeBegin = DateTime.Parse("06/18/2012"); //MM/DD/YYYY
request.SelectionDetails[0].ShipDateRangeEnd = request.SelectionDetails[0].ShipDateRangeBegin.AddDays(0);
request.SelectionDetails[0].ShipDateRangeBeginSpecified = false;
request.SelectionDetails[0].ShipDateRangeEndSpecified = false;
//
// Include detailed scans is optional.
// If omitted, set to false
request.ProcessingOptions = new TrackRequestProcessingOptionType[1];
request.ProcessingOptions[0] = TrackRequestProcessingOptionType.INCLUDE_DETAILED_SCANS;
return request;
}

private static void ShowTrackReply(TrackReply reply)
{
// Track details for each package
foreach (CompletedTrackDetail completedTrackDetail in reply.CompletedTrackDetails)
{
foreach (TrackDetail trackDetail in completedTrackDetail.TrackDetails)
{
Console.WriteLine("Tracking details:");
Console.WriteLine("**************************************");
ShowNotification(trackDetail.Notification);
Console.WriteLine("Tracking number: {0}", trackDetail.TrackingNumber);
Console.WriteLine("Tracking number unique identifier: {0}", trackDetail.TrackingNumberUniqueIdentifier);
Console.WriteLine("Track Status: {0} ({1})", trackDetail.StatusDetail.Description, trackDetail.StatusDetail.Code);
Console.WriteLine("Carrier code: {0}", trackDetail.CarrierCode);

if (trackDetail.OtherIdentifiers != null)
{
foreach (TrackOtherIdentifierDetail identifier in trackDetail.OtherIdentifiers)
{
Console.WriteLine("Other Identifier: {0} {1}", identifier.PackageIdentifier.Type, identifier.PackageIdentifier.Value);
}
}
if (trackDetail.Service != null)
{
Console.WriteLine("ServiceInfo: {0}", trackDetail.Service.Description);
}
if (trackDetail.PackageWeight != null)
{
Console.WriteLine("Package weight: {0} {1}", trackDetail.PackageWeight.Value, trackDetail.PackageWeight.Units);
}
if (trackDetail.ShipmentWeight != null)
{
Console.WriteLine("Shipment weight: {0} {1}", trackDetail.ShipmentWeight.Value, trackDetail.ShipmentWeight.Units);
}
if (trackDetail.Packaging != null)
{
Console.WriteLine("Packaging: {0}", trackDetail.Packaging);
}
Console.WriteLine("Package Sequence Number: {0}", trackDetail.PackageSequenceNumber);
Console.WriteLine("Package Count: {0} ", trackDetail.PackageCount);
if (trackDetail.ShipTimestampSpecified)
{
Console.WriteLine("Ship timestamp: {0}", trackDetail.ShipTimestamp);
}
if (trackDetail.DestinationAddress != null)
{
Console.WriteLine("Destination: {0}, {1}", trackDetail.DestinationAddress.City, trackDetail.DestinationAddress.StateOrProvinceCode);
}
if (trackDetail.ActualDeliveryTimestampSpecified)
{
Console.WriteLine("Actual delivery timestamp: {0}", trackDetail.ActualDeliveryTimestamp);
}
if (trackDetail.AvailableImages != null)
{
foreach (AvailableImageType ImageType in trackDetail.AvailableImages)
{
Console.WriteLine("Image availability: {0}", ImageType);
}
}
if (trackDetail.NotificationEventsAvailable != null)
{
foreach (EMailNotificationEventType notificationEventType in trackDetail.NotificationEventsAvailable)
{
Console.WriteLine("EmailNotificationEvent type : {0}", notificationEventType);
}
}

//Events
Console.WriteLine();
if (trackDetail.Events != null)
{
Console.WriteLine("Track Events:");
foreach (TrackEvent trackevent in trackDetail.Events)
{
if (trackevent.TimestampSpecified)
{
Console.WriteLine("Timestamp: {0}", trackevent.Timestamp);
}
Console.WriteLine("Event: {0} ({1})", trackevent.EventDescription, trackevent.EventType);
Console.WriteLine("***");
}
Console.WriteLine();
}
Console.WriteLine("**************************************");
}
}

}
private static void ShowNotification(Notification notification)
{
Console.WriteLine(" Severity: {0}", notification.Severity);
Console.WriteLine(" Code: {0}", notification.Code);
Console.WriteLine(" Message: {0}", notification.Message);
Console.WriteLine(" Source: {0}", notification.Source);
}
private static void ShowNotifications(TrackReply reply)
{
Console.WriteLine("Notifications");
for (int i = 0; i < reply.Notifications.Length; i++)
{
Notification notification = reply.Notifications[i];
Console.WriteLine("Notification no. {0}", i);
ShowNotification(notification);
}
}
private static bool usePropertyFile() //Set to true for common properties to be set with getProperty function.
{
return getProperty("usefile").Equals("True");
}
private static String getProperty(String propertyname) //Sets common properties for testing purposes.
{
try
{
String filename = "C:\\filepath\\filename.txt";
if (System.IO.File.Exists(filename))
{
System.IO.StreamReader sr = new System.IO.StreamReader(filename);
do
{
String[] parts = sr.ReadLine().Split(',');
if (parts[0].Equals(propertyname) && parts.Length == 2)
{
return parts[1];
}
}
while (!sr.EndOfStream);
}
Console.WriteLine("Property {0} set to default 'XXX'", propertyname);
return "XXX";
}
catch (Exception e)
{
Console.WriteLine("Property {0} set to default 'XXX'", propertyname);
return "XXX";
}
}
}
}

 

 

 

运行的时候出现这个问题

System.InvalidOperationException”类型的未经处理的异常在 System.Xml.dll 中发生

其他信息: 无法生成临时类(result=1)。

error CS0029: 无法将类型“TrackWebServiceClient.TrackServiceWebReference.EMailNotificationEventType”隐式转换为“TrackWebServiceClient.TrackServiceWebReference.EMailNotificationEventType[]”

 

 

有什么解决方法

五天的主页 五天 | 初学一级 | 园豆:8
提问于:2016-04-04 10:14
< >
分享
所有回答(1)
0

 trackDetail.NotificationEventsAvailable 只有一个 不是数组

死白的man | 园豆:2135 (老鸟四级) | 2016-04-05 20:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册