Fedex Service Integration Error (unable to generate a temporary class)
Asked Answered
F

3

11

I am trying to integrate Fedex Service in my asp.net website. I have downloaded the code from the Fedex website, but when I run this simple program I get an error, Check the following Code:

static void Main(string[] args)
{
    TrackRequest request = CreateTrackRequest();
    TrackService service = new TrackService();//I get Error Here 
    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();
}

The Following error on debugging occurred on TrackService service = new TrackService(); (line #5):

Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'TrackWebServiceClient.TrackServiceWebReference.EMailNotificationEventType' to 'TrackWebServiceClient.TrackServiceWebReference.EMailNotificationEventType[]'

Flowers answered 20/6, 2014 at 14:44 Comment(1)
Is TrackService just a 'POCO' that you can instantiate? If this is a web service I would think FedEx would provide a WSDL which you would then add to your project as a web reference, and then use the generated stub to call the 'track' method.Prostrate
S
26

This might be an issue with the way that WSDL.exe generates the client code.

You will have to manually edit Reference.cs file to replace double brackets [][] to single [] in EmailNotificationEventType definition.

From Microsoft:

There is no resolution available at this point. However, three workarounds are available:

  • You can generate the proxy class manually by using WSDL.exe and then change the proxy class in which the data type was inappropriately created as a two-dimensional array (for example, "CustomType[][]") so that it is a single-dimensional array (for example, "CustomType[]").
  • You can change the data type in the desired Web Services Description Language (WSDL) so that a second, optional element is included in the definition. You can do this by adding an element such as the following: <xs:element minOccurs="0" name="dummyElement" nillable="true" type="xs:string"/>
  • You can change the complex type in the desired WSDL so that the boundary attributes are part of the complex type instead of being part of the element. (That is, you can move the minOccurs and maxOccurs attributes to the complex type and then remove them from the element.)

Check also this link for further explanation.

Simply answered 20/6, 2014 at 15:8 Comment(3)
You will have to manually edit Reference.cs file to replace double brackets [][] to single [] in EmailNotificationEventType definition...it is working .. thanksFlowers
So this corrected my issue, however, I'm now not able to get the EmailNotifications from FedEx, and FedEx can't figure out why due to the request being correct. Did anyone else have this issue? (FYI: Messaging team already confirmed that the trackingupdates(at)fedex.com email address is whitelisted)Lytton
At first I tried the 3rd option, moving minOccurs/maxOccurs to comlex type and removing them from element, and while it worked locally, our Jenkins build failed with the original error message. I then tried the 1st option, using WSDL.exe to generate the class, removing the double brackets from the generated class, and adding the resulting .cs file to the project, and that worked.Blindfish
A
2

I tried the third option "You can change the complex type in the desired WSDL so that the boundary attributes are part of the complex type instead of being part of the element. (That is, you can move the minOccurs and maxOccurs attributes to the complex type and then remove them from the element.)" and it worked. The solution below:

Removed from the WSDL the minOccurs and maxOccurs for the NotificationEventsAvailable element [see the image below]

Screenshot

Arsyvarsy answered 27/7, 2016 at 19:43 Comment(3)
Please edit to include your code as code, rather than an image. It makes it easier for someone else to search for and read your answer.Sibship
Wow, thanks, I was getting the same message as the OP and this worked for me. I'm afraid I didn't think your description was very clear and I was unsure if it would work but it did. I just removed the "minOccurs" and "maxOccurs" attributes from the "NotificationEventsAvailable" element under the "TrackNotificationRecipientDetail" complex type (so line 1533 in .wsdl file), for those also unsure. You mentioned "move the min/max Occurs" but yeah it's just simply removing them.Blindfish
Quick update; I edited the .wsdl file and re-added the Web Reference and it seemed to work, until my co-worker notified me our Jenkins build was failing (an automated build-push service). I don't know for sure what happened, but it was throwing that original error from the OP. I ended up using the WSDL.exe tool to manually generate the proxy class, edit it to remove the double brackets [][], then add that .cs class to the project, giving it the same namespace as I used before w/ the Web Reference. Had to update some object names but it worked fine then.Blindfish
A
0

Fedex WSDL has an issue. Easiest way to resolve this is to replace

private NotificationEventType[][] recipientDetailsField;

with

private NotificationEventType[] recipientDetailsField;

in Reference.cs for FedexTrackingService. You can simply click on the TrackService() to access this file. Then search for "[][]". I believe it should be three replacement maybe two I am not sure. Just replace all "[][]" with "[]".

Keep in mind that any time you update FedexTrackingService in Web References, you need to do this procedure again.

Also, look for this function below and do the same thing.

public NotificationEventType[] RecipientDetails {
get {
    return this.recipientDetailsField;
}
set {
    this.recipientDetailsField = value;
}
Afire answered 16/2 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.