Azure-Samples / Cognitive-Speech-STT-ServiceLibrary

Service SDK - C# Samples, documentation for service to service speech to text
22 stars 26 forks source link

WebSocketException: The server returned status code '200' when status code '101' was expected. #4

Closed ian90911 closed 7 years ago

ian90911 commented 7 years ago

Hi, I downloaded sample code, sign up Bing Speech - Preview key, and executed sample code exe with command console: SpeechClientSample.exe [test wav file path] en-US Short [my Bing speech key] but I got exception: System.Net.WebSockets.WebSocketException: The server returned status code '200' when status code '101' was expected. Does the service("wss://speech.platform.bing.com/api/service/recognition") have accese limit or something I need setting? Thanks.

amrmahdi commented 7 years ago

You should only get such an error if you are using an https prefix (https://speech.platform.bing.com/api/service/recognition). It will wok only with wss prefix (wss://speech.platform.bing.com/api/service/recognition). I can repro the issue with an https url, but not with wss url.Can you confirm that you get the same behavior ?

ian90911 commented 7 years ago

@amrmahdi Thanks for reply, yes I'm sure I run it with wss prefix, because origin code is wss, I changed nothing code, only download, build and type arguments and execute command, so I'm confuse ... :S

amrmahdi commented 7 years ago

I could not repro the issue using the sample. Can you provide me with a requestIdentifier (a GUID passed to the RequestMetadata object) ?

ian90911 commented 7 years ago

@amrmahdi Here is my GUID :{7dd4e20f-d651-4fc8-b3e3-f60d99133e26} How I get it: At SpeechClientSample.Program.cs, Line 150 var requestMetadata = new RequestMetadata(Guid.NewGuid(), deviceMetadata, applicationMetadata, "SampleAppService"); change to var myguid = Guid.NewGuid(); var requestMetadata = new RequestMetadata(myguid, deviceMetadata, applicationMetadata, "SampleAppService"); And the wav file I use is from another sample project: Cognitive-Speech-STT-Windows-master\samples\SpeechRecognitionServiceExample\whatstheweatherlike.wav

amrmahdi commented 7 years ago

@ian90911 Sorry for the late reply. We still need some details to diagnose the issue. Could you please modify the sample to wrap the RecognizeAsync in a try/catch block as follows

try
{
    await speechClient.RecognizeAsync(new SpeechInput(audio, requestMetadata), this.cts.Token).ConfigureAwait(false);
}
catch (WebException we)
{
    foreach (var header in we.Response.Headers.AllKeys)
    {
        Console.WriteLine("{0} {1}", header, we.Response.Headers[header]);
    }
}

And let me know the output of the console printing above ? Thanks

ian90911 commented 7 years ago

@amrmahdi Thanks for reply. Here is the output:

X-MSEdge-Ref Ref A: 001BA1085B4B4822B6C1C2D570317FBE Ref B: TPE30EDGE0111 Ref C:
 Thu Feb  9 18:08:10 2017 PST
Content-Length 2176
Cache-Control no-store
Content-Type text/html
Date Fri, 10 Feb 2017 02:08:10 GMT
Server Microsoft-IIS/8.5
amrmahdi commented 7 years ago

@ian90911 sorry that this is taking more than expected. The last request you sent seemed to get 503 actually not the exception you mentioned in the original issue. Could try to repro it again ? If you are still getting the WebSocketException, please reply with a fiddler trace headers for the request, as it will not be caught with the WebException this time.

ian90911 commented 7 years ago

@amrmahdi Thanks for reply, here is the fiddler trace header log showed when I execute the command, and seems it get lot of request

(StartTime: 2017 feb 16  GMT+8  09:12:02.009) 
request: CONNECT api.cognitive.microsoft.com:443 HTTP/1.1 
response: HTTP/1.1 200 Connection Established
request: CONNECT speech.platform.bing.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT api.cognitive.microsoft.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT speech.platform.bing.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT api.cognitive.microsoft.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT speech.platform.bing.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT api.cognitive.microsoft.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT speech.platform.bing.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT api.cognitive.microsoft.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT speech.platform.bing.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established
request: CONNECT watson.microsoft.com:443 HTTP/1.1
response: HTTP/1.1 200 Connection Established

after last packet log, console throw the WebSocketException out.

And, I tried to run example at windows 8.1 (before was at windows7) and it just working well, I didn't know that ServerLibrary also need windows before windows 8. sorry for my careless 😓

amrmahdi commented 7 years ago

Oh now worries. Yes it only works on Windows 8+ because of the websockets support. I'll make sure we update the documentation to reflect that.