Stream does not support reading - stream

I have a problem with MemoryStream (.NET Core 3.1) on the IIS8.5 server. I am trying to create ZipArchive using MemoryStream and it works appropriately on a Local machine but doesn't work on the server. it responds to this message
{
"error": {
"message": "Stream does not support reading.",
"inner_message": "Stream does not support reading.\r\n",
"exception": "NotSupportedException"
}
}
may it be caused by any configuration of the IIS server?

Related

How do you send MIME format emails using Microsoft Graph Java SDK?

The official documentation does not provide an example for any SDK's (including the Java SDK): https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=java#example-4-send-a-new-message-using-mime-format. As there is no example, I have tried in vain to send the MIME content using the SDK (microsoft-graph 5.0.0):
Message sending = new Message();
ItemBody body = new ItemBody();
final String mimeMessageRFC822 = input.getMimeMessageRFC822();
body.content = Base64.getMimeEncoder().encodeToString(mimeMessageRFC822.getBytes());
sending.body = body;
GraphServiceClient service = getService(acHost, configuration);
service
.me()
.sendMail(UserSendMailParameterSet.newBuilder().withMessage(sending).withSaveToSentItems(true).build())
.buildRequest(new HeaderOption("Content-Type", "text/plain"))
.post();
The above code sets the request's content-type to text/plain, however the request body that is being sent is JSON (xxxxxx below is a placeholder for a valid Base64 encoded MIME content string).
{
"message":
{
"body":
{
"content": xxxxxx
}
},
"saveToSentItems": true
}
The response is a 404, stating:
GraphServiceException: Error code: ErrorMimeContentInvalidBase64String
Error message: Invalid base64 string for MIME content.
I can understand why it is responding with this error as the graph endpoint is parsing the text/plain content as base64 encoded MIME but finds the JSON structure instead. I have been on a video call with a Microsoft Graph support agent, and they have seen that my MIME content is valid. Sadly, they are not able to help with the Microsoft Graph Java SDK even though it is developed by Microsoft!
This suggests that we are not supposed to use the Java SDK at all for sending MIME formatted emails. Is this correct? Surely it can't be otherwise what is the point of a library that can receive MIME formatted emails but can't send them? Does anyone have a solution?
For now at least the solution is to send a CustomRequest with MIME content instead of using the fluent API provided by the Graph client.
final String encodedContent = Base64.getMimeEncoder().encodeToString(mimeMessageRFC822.getBytes());
CustomRequest<String> request = new CustomRequest<>(requestUrl, service, List.of(new HeaderOption("Content-Type", "text/plain")), String.class);
request.post(encodedContent);

Does the TFS Rest API support gzip encoding?

This is the REST API used to connect with Visual Studio Team Services (was Visual Studio Online), and on-premise TFS. I would like to set the headers so I can compress my requests, but the API documentation does not specify that gzip is supported. I'm hoping somebody might have experience.
using (var wc = new WebClient())
{
wc.Credentials = TfsCredentials;
wc.Headers[HttpRequestHeader.ContentEncoding] = "gzip";
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
var gzipByteArray = GZipBytes(serializedJson);
var uploadResponse = wc.UploadData(repoUri, gzipByteArray);
return Encoding.UTF8.GetString(uploadResponse);
}
Response is a 400, with the following error message:
The body of the request contains invalid Json. Parameter name: contentStream
I cannot find any documentation about this either. But I tested it with and without gzip compress from curl. The size of response is indeed compressed with gzip and the response can be decompressed correctly. So it should be supported.

Azure Mobile Service Offline Data Sync - Error on pullWithQuery

I am using Azure Mobile Service as a backend. Data structure is implemented and I tested CRUD calls using Fiddler. Everything seems right.
Then I implemented offline data synchronization with a client iOS device. Btw I followed this tutorial: https://azure.microsoft.com/en-gb/documentation/articles/app-service-mobile-ios-get-started-offline-data-preview/
My problem is when I try to synchronize data using the pullWithQuery function. I get this errror:
2015-08-19 11:36:12.525 Hykso[1820:330268] Logged in as Facebook:10155931659265500
2015-08-19 11:36:30.285 Hykso[1820:330522] ERROR Error Domain=com.Microsoft.WindowsAzureMobileServices.ErrorDomain Code=-1302 "{"message":"An error has occurred."}" UserInfo=0x14671c30 {NSLocalizedDescription={"message":"An error has occurred."}, com.Microsoft.WindowsAzureMobileServices.ErrorResponseKey=<NSHTTPURLResponse: 0x14584de0> { URL: https://hyksomobileservice.azure-mobile.net/tables/Athlete?$top=50&__includeDeleted=true&$skip=0&__systemProperties=__createdAt%2C__updatedAt%2C__deleted%2C__version } { status code: 500, headers {
"Cache-Control" = "no-cache";
"Content-Length" = 36;
"Content-Type" = "application/json; charset=utf-8";
Date = "Wed, 19 Aug 2015 15:36:28 GMT";
Expires = 0;
Pragma = "no-cache";
Server = "Microsoft-IIS/8.0";
"X-Powered-By" = "ASP.NET";
} }, com.Microsoft.WindowsAzureMobileServices.ErrorRequestKey=<NSMutableURLRequest: 0x14657830> { URL: https://hyksomobileservice.azure-mobile.net/tables/Athlete?$top=50&__includeDeleted=true&$skip=0&__systemProperties=__createdAt%2C__updatedAt%2C__deleted%2C__version }}
I just tested the same get call using Fiddler and I get this message:
exceptionMessage=The specified type member 'Version' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Does anyone have some advice to give me in order to debug this? Thank you!
(First off, make sure you use the Mobile Services topic, not Mobile Apps topic. For this article they are very similar, so that's not your issue.)
The error looks really strange, and it points to something wrong with your server setup. Your client is sending a query asking for the system properties __createdAt, __updatedAt, __deleted, and __version, but somehow the "version" part is being translated into an invalid LINQ query. If you remove the ms_version column from your Core Data model, then version won't be requested, but then you can't do any conflict handling.
Based on the EF error message, you must be using the .NET backend. What happens when you test with the default TodoItem type that's in the server project? Your data class needs to extend EntityData to ensure everything is mapped correctly. (You can use ITableData, but that's more advanced.)
In terms of debugging, you can run the server project locally on IIS express and set a breakpoint after hitting the endpoint via Fiddler. You can also use remote debugging to go to your actual remote service.
For tutorials on this, see:
https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-troubleshoot/#runtime-debugging
https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-troubleshoot-visual-studio/
Are assigning any value to the Version column in your data? I developed my app with C# and had a similar problem. There were two constraints about Version. First, don't touch it on the client just define it in your model and never assign to it. Second, in C# we need to define it this way
[Version]
public byte[] Version { get; set; }
I don't know the equivalent of [Version] in Objective-c

Support compression in .NET OData 4 Client

Problem
I have added support for http compression in our self-hosted OWIN/Katana Web API OData 4 service but I do not see how to support compression in the .NET client. I'm using OData libraries v6.5.0 and I need to support compression/decompression in the client (OData v4 Client Code Generator). I am using Deflate encoding for the compression via an ActionFilter. Everything compresses correctly on the server as confirmed via Fiddler but I do not know how to configure the client to support this now that the OData client uses the Request and Response Pipelines instead of the now defunct WritingRequest and RecievingResponse events that once supported this very scenario.
Attempts
By experimentation I found that I can hook into the ReceivingResponse event on my DataServiceContext and then call ReceivingResponseEventArgs.ResponseMessage.GetStream() but I don't know what to do to overwrite the message content correctly. If I CopyTo() on the stream, I get a null reference exception at Microsoft.OData.Core.ODataMessageReader.DetectPayloadKind(). I presume this is because the stream was read to the end and the position needs to be set back to zero but I cannot do that because the stream also throws an exception when setting the position back because it says it does not support seeking. I presume this is simply due to the stream being read-only. Even if I could copy the stream to decompress it successfully, how do I modify the response message content with the decompressed content? I don't see any hooks for this at all in the RequestPipeline or ResponsePipeline. To clarify, I want to decompress the response message content and then set it for the materialization that occurs soon after, how might I do that? Extra credit for how to also send compressed requests to the OData service. Thanks!
OData client use the HTTPWebRequest and HTTPWebReponse, which supports the compression well. Try setting the AutomaticDecompression of HTTPWebRequest to Deflate or GZip, in SendingRequest2 pipeline event, like this:
private void OnSendingRequest_(object sender, SendingRequest2EventArgs args)
{
if (!args.IsBatchPart) // The request message is not HttpWebRequestMessage in batch part.
{
HTTPWebRequest request = ((HttpWebRequestMessage)args.RequestMessage).HttpWebRequest;
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
}
Then in response, HTTPWebResponse will decompress the stream automatically, before the materialization work.

Rikulo websockets and channels

Does rikulo stream v 0.7.2 support web sockets with different channels?
I have seen so far only examples with static resource files.
To handle Web Socket, you can use WebSocketTransformer to upgrade HTTP connection to WebSocket connection:
new StreamServer(uriMapping: {
"/cmd", (HttpConnect connect) =>
WebSocketTransformer.upgrade(connect.request)
.then((websocket) {
websocket.listen((evt) {
websocket.add("Server received: $evt");
});
return socket.done;
})
}).start();
Note: Web Socket is supported directly since Rikulo Stream 0.8.0. Please refer to the WebSocket Handling section.

Resources