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[]'

Mohamad Mahmoud Darwish
  • 3,865
  • 9
  • 51
  • 76
  • 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. – public wireless Jun 20 '14 at 15:13

2 Answers2

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.

Community
  • 1
  • 1
mai
  • 464
  • 4
  • 23
  • 1
    You will have to manually edit Reference.cs file to replace double brackets [][] to single [] in EmailNotificationEventType definition...it is working .. thanks – Mohamad Mahmoud Darwish Jun 20 '14 at 15:41
  • 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) – Ryan C Sep 17 '15 at 21:00
  • 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. – clamum May 03 '21 at 15:28
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

Chandresh Khambhayata
  • 1,748
  • 2
  • 31
  • 60
Costi
  • 31
  • 3
  • 1
    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. – user812786 Jul 27 '16 at 20:06
  • 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. – clamum Apr 28 '21 at 19:08
  • 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. – clamum May 03 '21 at 15:25