locked
Multiple Calls To Translate() Succeed, Then Fail: 400 Bad Request RRS feed

  • Question

  • I'm writing an app to translate XLIFF content automatically via Bing Translator. I iterate over the <trans-unit> elements, pull out the <target> element value, and pass it to Bing Translator using the Translate method. The first 494 seem to work fine and then the service call stops working for a period of time. I've tried having my application sleep for 10 seconds and get a new access token, but this doesn't seem to solve the problem. I've tried resetting the connection before it gets to 5000 characters translated. Without explanation, the service stops working for a while, then starts working again...then fails again...then starts up again.

    Is there some kind of characters-per-minute limit? I've seen that there is a 10-minute limit on access tokens and I know there is a max limit on characters per request, but these should all be well below that limit.

    Thanks for any help that anyone can offer.

    Here is a log of when the service fails. If there is no entry, such as 1 through 494, the translation has succeeded.

    EXCEPTION: totalChars: 14334 :: totalReqs: 495 :: strSource: DPO7000 Series

    EXCEPTION: totalChars: 14342 :: totalReqs: 496 :: strSource: Opt. LSA
    EXCEPTION: totalChars: 14350 :: totalReqs: 497 :: strSource: Opt. LSA
    EXCEPTION: totalChars: 14356 :: totalReqs: 498 :: strSource: Probes
    EXCEPTION: totalChars: 14468 :: totalReqs: 499 :: strSource: TCP0030 AC/DC Current Probe, TDP1000 or TDP0500 High Voltage Differential Probes, P5050 or P6139B Passive Probes
    EXCEPTION: totalChars: 14477 :: totalReqs: 500 :: strSource: 1 or more
    EXCEPTION: totalChars: 14486 :: totalReqs: 501 :: strSource: 1 or more
    EXCEPTION: totalChars: 14495 :: totalReqs: 502 :: strSource: 1 or more
    EXCEPTION: totalChars: 14509 :: totalReqs: 503 :: strSource: Logic Analyzer
    EXCEPTION: totalChars: 14524 :: totalReqs: 504 :: strSource: TLA5000B Series
    EXCEPTION: totalChars: 14525 :: totalReqs: 505 :: strSource: 1
    EXCEPTION: totalChars: 14526 :: totalReqs: 506 :: strSource: 1
    EXCEPTION: totalChars: 14527 :: totalReqs: 507 :: strSource: 1
    EXCEPTION: totalChars: 14543 :: totalReqs: 508 :: strSource: Signal Generator
    EXCEPTION: totalChars: 14557 :: totalReqs: 509 :: strSource: AFG3000 Series
    EXCEPTION: totalChars: 14558 :: totalReqs: 510 :: strSource: 1
    EXCEPTION: totalChars: 14559 :: totalReqs: 511 :: strSource: 1
    EXCEPTION: totalChars: 14560 :: totalReqs: 512 :: strSource: 1
    EXCEPTION: totalChars: 14568 :: totalReqs: 513 :: strSource: Ethernet
    EXCEPTION: totalChars: 14575 :: totalReqs: 514 :: strSource: Product
    EXCEPTION: totalChars: 14586 :: totalReqs: 515 :: strSource: Description
    EXCEPTION: totalChars: 14604 :: totalReqs: 516 :: strSource: 10/100/1000 BASE-T
    EXCEPTION: totalChars: 14620 :: totalReqs: 517 :: strSource: 10GBASE-T(XGbT)
    EXCEPTION: totalChars: 14633 :: totalReqs: 518 :: strSource: 10/40/100 GbE
    EXCEPTION: totalChars: 14643 :: totalReqs: 519 :: strSource: Cable Test
    EXCEPTION: totalChars: 14655 :: totalReqs: 520 :: strSource: Oscilloscope
    EXCEPTION: totalChars: 14682 :: totalReqs: 521 :: strSource: MSO/DPO4000B with DPO4ENET*
    EXCEPTION: totalChars: 14684 :: totalReqs: 522 :: strSource: 1*
    EXCEPTION: totalChars: 14711 :: totalReqs: 523 :: strSource: MSO/DPO5000 with option ET3
    EXCEPTION: totalChars: 14712 :: totalReqs: 524 :: strSource: 1
    EXCEPTION: totalChars: 14735 :: totalReqs: 525 :: strSource: DPO7000 with option ET3
    EXCEPTION: totalChars: 14736 :: totalReqs: 526 :: strSource: 1
    EXCEPTION: totalChars: 14769 :: totalReqs: 527 :: strSource: DPO/DSA/MSO70000 with option XGbT
    EXCEPTION: totalChars: 14770 :: totalReqs: 528 :: strSource: 1
    EXCEPTION: totalChars: 14776 :: totalReqs: 529 :: strSource: Probes
    EXCEPTION: totalChars: 14810 :: totalReqs: 530 :: strSource: TDP1500 Series Differential Probes
    EXCEPTION: totalChars: 14811 :: totalReqs: 531 :: strSource: 2
    EXCEPTION: totalChars: 14859 :: totalReqs: 532 :: strSource: P6247, P6248 or P6330 Series Differential Probes
    EXCEPTION: totalChars: 14860 :: totalReqs: 533 :: strSource: 2
    EXCEPTION: totalChars: 18162 :: totalReqs: 727 :: strSource: AWG7082C, AWG7102 (HS-Gear1 Only) or AWG7122B/C without Interleave option 06 (HS-Gear1&2 Only), or AWG7122B/C with Interleave option 06 (All HS-Gears), or higher
    EXCEPTION: totalChars: 18163 :: totalReqs: 728 :: strSource: 1
    EXCEPTION: totalChars: 18164 :: totalReqs: 729 :: strSource: 1
    EXCEPTION: totalChars: 18182 :: totalReqs: 730 :: strSource: PG3ACAB or PG3AMOD
    EXCEPTION: totalChars: 18183 :: totalReqs: 731 :: strSource: 1
    EXCEPTION: totalChars: 18184 :: totalReqs: 732 :: strSource: 1
    EXCEPTION: totalChars: 18200 :: totalReqs: 733 :: strSource: Generator Probes
    EXCEPTION: totalChars: 18229 :: totalReqs: 734 :: strSource: P332 MIPI DPhy Probe for PG3A
    EXCEPTION: totalChars: 18230 :: totalReqs: 735 :: strSource: 1
    EXCEPTION: totalChars: 18231 :: totalReqs: 736 :: strSource: 1
    EXCEPTION: totalChars: 18253 :: totalReqs: 737 :: strSource: D-PHY Coupler for PG3A
    EXCEPTION: totalChars: 18254 :: totalReqs: 738 :: strSource: 1
    EXCEPTION: totalChars: 18272 :: totalReqs: 739 :: strSource: Generator Software
    EXCEPTION: totalChars: 18289 :: totalReqs: 740 :: strSource: PGRemote Software
    EXCEPTION: totalChars: 18290 :: totalReqs: 741 :: strSource: 1
    EXCEPTION: totalChars: 18291 :: totalReqs: 742 :: strSource: 1
    EXCEPTION: totalChars: 18304 :: totalReqs: 743 :: strSource: SerialXpressr
    EXCEPTION: totalChars: 18316 :: totalReqs: 744 :: strSource: 1 (Optional)
    EXCEPTION: totalChars: 18330 :: totalReqs: 745 :: strSource: Logic Analyzer
    EXCEPTION: totalChars: 18344 :: totalReqs: 746 :: strSource: TLA6000 Series
    EXCEPTION: totalChars: 18345 :: totalReqs: 747 :: strSource: 1
    EXCEPTION: totalChars: 18366 :: totalReqs: 748 :: strSource: Logic Analyzer Probes
    EXCEPTION: totalChars: 18392 :: totalReqs: 749 :: strSource: P6980 Logic Analyzer Probe
    EXCEPTION: totalChars: 18393 :: totalReqs: 750 :: strSource: 1
    EXCEPTION: totalChars: 18435 :: totalReqs: 751 :: strSource: DPHYPRE DPHY Preprocessor for CS12 and DSI
    EXCEPTION: totalChars: 18436 :: totalReqs: 752 :: strSource: 1
    EXCEPTION: totalChars: 18459 :: totalReqs: 753 :: strSource: Logic Analyzer Software
    EXCEPTION: totalChars: 18510 :: totalReqs: 754 :: strSource: MIPI TLA SW CSI- or DSI-specific for Logic Analyzer
    EXCEPTION: totalChars: 18511 :: totalReqs: 755 :: strSource: 1
    EXCEPTION: totalChars: 18528 :: totalReqs: 756 :: strSource: Other Accessories
    EXCEPTION: totalChars: 18554 :: totalReqs: 757 :: strSource: Matched pair of SMA cables
    EXCEPTION: totalChars: 18555 :: totalReqs: 758 :: strSource: 2
    EXCEPTION: totalChars: 18565 :: totalReqs: 759 :: strSource: GPIB cable
    EXCEPTION: totalChars: 18566 :: totalReqs: 760 :: strSource: 1
    EXCEPTION: totalChars: 18616 :: totalReqs: 761 :: strSource: Rise Time Filter -120 psec with barrel connectors
    EXCEPTION: totalChars: 18617 :: totalReqs: 762 :: strSource: 2
    EXCEPTION: totalChars: 18655 :: totalReqs: 763 :: strSource: BiasTee of AWG Interleave for HS-Gear3
    EXCEPTION: totalChars: 18656 :: totalReqs: 764 :: strSource: 2
    EXCEPTION: totalChars: 18674 :: totalReqs: 765 :: strSource: TCA-SMA connectors
    EXCEPTION: totalChars: 18684 :: totalReqs: 766 :: strSource: 2 Optional
    EXCEPTION: totalChars: 18739 :: totalReqs: 767 :: strSource: PCI Express: Electrical Compliance / Debug & Validation
    EXCEPTION: totalChars: 18746 :: totalReqs: 768 :: strSource: Product
    EXCEPTION: totalChars: 18757 :: totalReqs: 769 :: strSource: Description
    EXCEPTION: totalChars: 18760 :: totalReqs: 770 :: strSource: 1.x
    EXCEPTION: totalChars: 18763 :: totalReqs: 771 :: strSource: 2.0
    EXCEPTION: totalChars: 18766 :: totalReqs: 772 :: strSource: 3.0
    EXCEPTION: totalChars: 18785 :: totalReqs: 773 :: strSource: Transmitter Testing
    EXCEPTION: totalChars: 18832 :: totalReqs: 774 :: strSource: DPO/DSA70604 or higher with options DJA and PCE
    EXCEPTION: totalChars: 18833 :: totalReqs: 775 :: strSource: 1
    EXCEPTION: totalChars: 18885 :: totalReqs: 776 :: strSource: DPO/DSA71254 or higher with options DJA, PCE and SLA
    EXCEPTION: totalChars: 18886 :: totalReqs: 777 :: strSource: 1
    EXCEPTION: totalChars: 18940 :: totalReqs: 778 :: strSource: DPO/DSA71604 or higher with options DJA, PCE3, and SLA
    EXCEPTION: totalChars: 18941 :: totalReqs: 779 :: strSource: 1
    EXCEPTION: totalChars: 18949 :: totalReqs: 780 :: strSource: Software
    EXCEPTION: totalChars: 18984 :: totalReqs: 781 :: strSource: SigTest from PCI-SIG (members only)
    EXCEPTION: totalChars: 18985 :: totalReqs: 782 :: strSource: 1
    EXCEPTION: totalChars: 18986 :: totalReqs: 783 :: strSource: 1
    EXCEPTION: totalChars: 18996 :: totalReqs: 784 :: strSource: SLA Option
    EXCEPTION: totalChars: 18997 :: totalReqs: 785 :: strSource: 1
    EXCEPTION: totalChars: 19015 :: totalReqs: 786 :: strSource: DPOJET-PCE3 Option
    EXCEPTION: totalChars: 19016 :: totalReqs: 787 :: strSource: 1
    EXCEPTION: totalChars: 19017 :: totalReqs: 788 :: strSource: 1
    EXCEPTION: totalChars: 19018 :: totalReqs: 789 :: strSource: 1
    EXCEPTION: totalChars: 19035 :: totalReqs: 790 :: strSource: ICONN S Parameter
    EXCEPTION: totalChars: 19036 :: totalReqs: 791 :: strSource: 1
    EXCEPTION: totalChars: 19061 :: totalReqs: 792 :: strSource: De-Embedding Channel Test
    EXCEPTION: totalChars: 19068 :: totalReqs: 793 :: strSource: DSA8300
    EXCEPTION: totalChars: 19069 :: totalReqs: 794 :: strSource: 1
    EXCEPTION: totalChars: 19085 :: totalReqs: 795 :: strSource: 80E08 TDR Module
    EXCEPTION: totalChars: 19086 :: totalReqs: 796 :: strSource: 2
    EXCEPTION: totalChars: 19092 :: totalReqs: 797 :: strSource: Probes
    EXCEPTION: totalChars: 19113 :: totalReqs: 798 :: strSource: P7300 or P7500 Series
    EXCEPTION: totalChars: 19114 :: totalReqs: 799 :: strSource: 1
    EXCEPTION: totalChars: 19115 :: totalReqs: 800 :: strSource: 1
    EXCEPTION: totalChars: 19131 :: totalReqs: 801 :: strSource: Receiver Testing
    EXCEPTION: totalChars: 19175 :: totalReqs: 802 :: strSource: BERTScope BSA85C with options STR and PCISTR
    EXCEPTION: totalChars: 19176 :: totalReqs: 803 :: strSource: 1
    EXCEPTION: totalChars: 19177 :: totalReqs: 804 :: strSource: 1
    EXCEPTION: totalChars: 19225 :: totalReqs: 805 :: strSource: BERTScope BSA85Cwith options STR, PVU and PCISTR
    EXCEPTION: totalChars: 19226 :: totalReqs: 806 :: strSource: 1
    EXCEPTION: totalChars: 19261 :: totalReqs: 807 :: strSource: BERTScope DPP125 3TAP Pre-Emphasis
    EXCEPTION: totalChars: 19262 :: totalReqs: 808 :: strSource: 1
    EXCEPTION: totalChars: 19335 :: totalReqs: 809 :: strSource: BERTSScope CR125A Clock Recovery Module with Option CR125ACBL (Cable Set)
    EXCEPTION: totalChars: 19336 :: totalReqs: 810 :: strSource: 1
    EXCEPTION: totalChars: 19360 :: totalReqs: 811 :: strSource: Compliance Test Fixtures
    EXCEPTION: totalChars: 19392 :: totalReqs: 812 :: strSource: PCI-SIG Fixturing Available here
    EXCEPTION: totalChars: 19393 :: totalReqs: 813 :: strSource: 1
    EXCEPTION: totalChars: 19394 :: totalReqs: 814 :: strSource: 1
    EXCEPTION: totalChars: 19395 :: totalReqs: 815 :: strSource: 1
    EXCEPTION: totalChars: 19434 :: totalReqs: 816 :: strSource: PCI Express: Digital Debug & Validation
    EXCEPTION: totalChars: 19441 :: totalReqs: 817 :: strSource: Product
    EXCEPTION: totalChars: 19452 :: totalReqs: 818 :: strSource: Description
    EXCEPTION: totalChars: 19455 :: totalReqs: 819 :: strSource: 1.x
    EXCEPTION: totalChars: 19458 :: totalReqs: 820 :: strSource: 2.0
    EXCEPTION: totalChars: 19461 :: totalReqs: 821 :: strSource: 3.0
    EXCEPTION: totalChars: 19475 :: totalReqs: 822 :: strSource: Logic Analyzer
    EXCEPTION: totalChars: 19489 :: totalReqs: 823 :: strSource: TLA7000 Series
    EXCEPTION: totalChars: 19490 :: totalReqs: 824 :: strSource: 1
    EXCEPTION: totalChars: 19491 :: totalReqs: 825 :: strSource: 1
    EXCEPTION: totalChars: 19492 :: totalReqs: 826 :: strSource: 1
    EXCEPTION: totalChars: 19522 :: totalReqs: 827 :: strSource: Logic Protocol Analyzer Module
    EXCEPTION: totalChars: 19537 :: totalReqs: 828 :: strSource: TLA7SA00 Series
    EXCEPTION: totalChars: 19538 :: totalReqs: 829 :: strSource: 1
    EXCEPTION: totalChars: 19539 :: totalReqs: 830 :: strSource: 1
    EXCEPTION: totalChars: 19540 :: totalReqs: 831 :: strSource: 1
    EXCEPTION: totalChars: 19561 :: totalReqs: 832 :: strSource: Logic Analyzer Probes
    EXCEPTION: totalChars: 19610 :: totalReqs: 833 :: strSource: P67SA00 Series midbus, interposer, or solder-down
    EXCEPTION: totalChars: 19619 :: totalReqs: 834 :: strSource: 1 or more
    EXCEPTION: totalChars: 19628 :: totalReqs: 835 :: strSource: 1 or more
    EXCEPTION: totalChars: 19637 :: totalReqs: 836 :: strSource: 1 or more
    EXCEPTION: totalChars: 19644 :: totalReqs: 837 :: strSource: RapidIO
    EXCEPTION: totalChars: 19651 :: totalReqs: 838 :: strSource: Product
    EXCEPTION: totalChars: 19662 :: totalReqs: 839 :: strSource: Description
    EXCEPTION: totalChars: 19670 :: totalReqs: 840 :: strSource: Quantity
    EXCEPTION: totalChars: 19692 :: totalReqs: 841 :: strSource: Real Time Oscilloscope
    EXCEPTION: totalChars: 19706 :: totalReqs: 842 :: strSource: DPO7000 Series
    EXCEPTION: totalChars: 19707 :: totalReqs: 843 :: strSource: 1
    EXCEPTION: totalChars: 19728 :: totalReqs: 844 :: strSource: Sampling Oscilloscope
    EXCEPTION: totalChars: 19742 :: totalReqs: 845 :: strSource: DSA8300 Series
    EXCEPTION: totalChars: 19743 :: totalReqs: 846 :: strSource: 1
    EXCEPTION: totalChars: 19750 :: totalReqs: 847 :: strSource: Modules
    EXCEPTION: totalChars: 19795 :: totalReqs: 848 :: strSource: 80E08 TDR / 80E07 Electrical Sampling Modules
    EXCEPTION: totalChars: 19844 :: totalReqs: 849 :: strSource: 80A05 and 80A07 Electrical Clock Recovery Modules

    Tuesday, November 20, 2012 11:10 PM

All replies

  • Hi EchoNW,

    SSome users have reported this 400 error, which seems to be related to a registration issue for the app or for the API.
    Would you mind checking the following on your end?  Let us know how it goes.  Thanks.  Takako (Microsoft Translator team)

    • Visit https://datamarket.azure.com/developer/applications -- Is your app listed here? If so, use the Client ID and Client Secret for this entry, and not the account-wide Client ID that you got when you signed up for Azure. If not, register one from this screen, and use its Client ID and Client Secret.
    • Visit https://datamarket.azure.com/account/datasets -- Is Microsoft Translator listed here as a service that you have subscribed to? Is it Active? Do you have enough characters left in your subscription?
    Wednesday, November 21, 2012 12:09 AM
  • Hey Takako Aikawa,

    Thank you for the quick response. I am using the correct Client ID and Client Secret from the the first page you sent and Microsoft Translator is listed on the second page and it is marked as Active, however it is showing that my remaining characters are still at 2,000,000 characters. I've tested probably 100,000 characters today, so that number does't seem to be affected. Does that mean that my account is not setup correctly?

    Thank you!

    Wednesday, November 21, 2012 12:15 AM
  • Hi EchoNW,

    Not sure what’s going on but one way to test is to create new client ID and client Secret and replace the existing ones with the new ones to see what would happen?  Follow the steps described below:

    • Sign in to https://datamarket.azure.com/.  At the bottom of the page you’ll see the read called ‘Develop’, and under it you’ll see a link that says ‘Register your Application’.   Select this, and you’ll be taken to the screen that allows you register your application.
    • You need to type in your Client ID and Name.  Client Secret should be already given.
    • Make sure that you write down your Client ID and Client Secret while you’re on the Register your application page.

    Let me know how it goes.  Takako (Microsoft Translator Team)

    Wednesday, November 21, 2012 1:55 AM
  • Thanks for your reply, Takako. I'm off of work for the holiday, so I'll let you know how it goes when I get back next week. Again, I appreciate your help. :)
    Wednesday, November 21, 2012 10:08 AM
  • Hi EchoNW,

    please also look at the value of the exception - it will contain the error detail, helps you (and us) determine what the observed problem was.

    Do you specify the source language? If not, you may have seen a parameter error, which happens when the detection result is a language that is not supported in translation.

    Let us know how it goes,
    Chris Wendt
    Microsoft Translator

    Wednesday, November 21, 2012 4:27 PM
  • Hey Chris,

    I just ran this again this morning, so if it's on the server end, it's still happening. The exception is the 400 Bad Request I mentioned above. The full exception printout is below. I am specifying a language and many of my requests succeed with the same parameters, only changing the string value. As I described above, it seems to work fine for a certain period of time, then stops working for some time, then starts up again...and repeats failing and succeeding. I'm not changing the language or any parameters other than the string I'm translating. My guess is that I'm either hitting some kind of limit on max requests or characters per time period or my authentication header is expiring, although this entire block runs in less than 10 minutes and I've tried resetting the authentication header after 5000 characters.

    Thanks for your help!

    System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       --- End of inner exception stack trace ---

    Server stack trace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at MachineTranslateLibrary.TranslatorService.LanguageService.Translate(String appId, String text, String from, String to, String contentType, String category)
       at MachineTranslateLibrary.TranslatorService.LanguageServiceClient.Translate(String appId, String text, String from, String to, String contentType, String category) in C:\code\dsag\drupal_translation\tool-projects\XLIFFMachineTranslationSuite\MachineTranslateLibrary\Service References\TranslatorService\Reference.cs:line 830
       at MachineTranslateLibrary.BingTranslator.GetStringTranslation(String strSource) in C:\code\dsag\drupal_translation\tool-projects\XLIFFMachineTranslationSuite\MachineTranslateLibrary\BingTranslator.cs:line 109

    Monday, November 26, 2012 5:58 PM
  • I'm not sure if this will help at all, but here's my method to translate strings. I initialize the object, create the authentication header, then iterate over an XLIFF file making a call to this method to translate strings. You can see where I'm resetting the connection and sleeping just in case it's a request timing issue. Adding this didn't fix it.

    public string GetStringTranslation(string strSource)
    {
        try
        {
            // if charsCount plus the next string length exceeds the maximum chars per session, reset the connection
            if ((this.charsCount + strSource.Length) >= MAX_CHARS_PER_SESSION)
            {
                Thread.Sleep(10000);
                Console.WriteLine("SLEEP: charsCount " + this.charsCount);
                this.SetupRequest(this.targetLang);
                this.charsCount = 0;
            } // end if test
    
            // Creates a block within which an OperationContext object is in scope.
            using (OperationContextScope scope = new OperationContextScope(this.client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = this.httpRequestProperty;
    
                // only translate non-empty strings
                if (strSource.Trim().Length > 0)
                {
                    // increment charsCount to keep track of how many characters we've translated for this session
                    this.charsCount = this.charsCount + strSource.Length;
                    this.totalChars = this.totalChars + strSource.Length;
                    this.totalReqs = this.totalReqs + 1;
    
                    try
                    {
                        //Keep appId parameter blank as we are sending access token in authorization header.
                        strTarget = this.client.Translate("", strSource, "en", this.targetLang, "text/html", "general");
                    } // end try
                    catch (Exception e)
                    {
                        Console.WriteLine("EXCEPTION: " + "totalChars: " + this.totalChars + " :: totalReqs: " + this.totalReqs + " :: strSource: " + strSource);
                        Console.WriteLine("--> " + e.ToString());
                    } // end catch
                } // end if test
            } // end using scope
        } // end try
        catch (Exception e)
        {
            throw new Exception("BingTranslator exception: " + e.Message);
        } // end catch
    
        return strTarget;
    } // end GetStringTranslation method

    Monday, November 26, 2012 6:32 PM
  • Hi EchoNW -- have you ensured that you have an application registered here: https://datamarket.azure.com/developer/applications and that you are using the ClientID and Client Secret for that application? (If it is registered on that page, click the 'Edit' link to see them)
    Tuesday, November 27, 2012 1:45 PM
  • Laurence,

    Yes, that was the original responder 's suggestion. Again, this is working for many requests, then fails, then works again, then fails again, and so on, all within the same session using the same authentication parameters. It's not the ClientID or Client Secret that is the problem. I can process nearly 500 requests before it starts failing.

    Thanks.

    Tuesday, November 27, 2012 5:23 PM
  • When you get the token from Azure, it lasts for 10 minutes. Are your 500 requests taking longer than that? If so, you should get the token again every 10 minutes (or every 9 minutes , just to be safe) :)

    I see you have a Thread.Sleep for 10 seconds, so 500 requests x 10 seconds = 5000 seconds, which is > 10 minutes...

    Tuesday, November 27, 2012 7:36 PM
  • I only sleep for 10 seconds after 5000 characters have been sent. This was only done to try to fix the problem after it already occurred. The entire thing runs in about 5 minutes, even with failures. I'm processing waaaaay more than 500 requests (I think close to 4,000+) during that 5 minutes or so. It fails with or without the sleep, and that's after it succeeds for several hundred.

    Tuesday, November 27, 2012 8:32 PM
  • I think this problem may be solved. Strangely, removing an efficiency I was trying to utilize seemed to have fixed it. I was caching the connection so I didn't call it every time I made a call to the translate() service. Turns out that was what was causing the issue, as far as I can tell. I moved that connection block back into my method and I create a new connection for every request now and it seems to have solved the issue.

    public string GetStringTranslation(string strSource)
            {
                this.strTarget = "";
    
                try
                {
                    Console.WriteLine("New request: " + this.totalReqs);
                    this.targetLang = this.GetLanguageCode(targetLang);
    
                    this.client = new TranslatorService.LanguageServiceClient();
                    this.strTarget = "";
                    this.admAuth = new AdmAuthentication(this.clientID, this.secretPhrase);
    
                    try
                    {
                        this.admToken = admAuth.GetAccessToken();
                        this.tokenReceived = DateTime.Now;
                        // Create a header with the access_token property of the returned token
                        this.authToken = "Bearer " + this.admToken.access_token;
    
                        //Set Authorization header before sending the request
                        this.httpRequestProperty = new HttpRequestMessageProperty();
                        this.httpRequestProperty.Method = "POST";
                        this.httpRequestProperty.Headers.Add("Authorization", this.authToken);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("BingTranslator exception: " + e.Message);
                    }
    
                    if (strSource.Length > 9999)
                    {
                        throw new Exception("BingTranslator exception: translation string length larger than 10,000 characters");
                    } // end if test
    
                    // Creates a block within which an OperationContext object is in scope.
                    using (OperationContextScope scope = new OperationContextScope(this.client.InnerChannel))
                    {
                        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = this.httpRequestProperty;
    
                        // only translate non-empty strings
                        if (strSource.Trim().Length > 0)
                        {
                            // increment charsCount to keep track of how many characters we've translated for this session
                            this.charsCount = this.charsCount + strSource.Length;
                            this.totalChars = this.totalChars + strSource.Length;
                            this.totalReqs = this.totalReqs + 1;
    
                            try
                            {
                                //Keep appId parameter blank as we are sending access token in authorization header.
                                strTarget = this.client.Translate("", strSource, "en", this.targetLang, "text/html", "general");
                            } // end try
                            catch (Exception e)
                            {
                                Console.WriteLine("EXCEPTION: " + "totalChars: " + this.totalChars + " :: totalReqs: " + this.totalReqs + " :: strSource: " + strSource);
                                //Console.WriteLine("--> " + e.ToString());
                            } // end catch
                        } // end if test
                    } // end using scope
                } // end try
                catch (Exception e)
                {
                    throw new Exception("BingTranslator exception: " + e.Message);
                } // end catch
    
                return strTarget;
            } // end GetStringTranslation method

    Wednesday, November 28, 2012 10:22 PM
  • I'm glad you got it working!

    Out of interest -- is your subscription now showing usage? You had mentioned before that you weren't seeing the character count go down.

    Friday, November 30, 2012 7:37 PM