Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all 7925 articles
Browse latest View live

Edited Unassigned: [Regression]XmlMediaTypeFormatter does not serialize Uri input correctly [1070]

$
0
0
Uri- file://[7f:d:ee9e::7a:828e:c]/-861%A3+/F3&m/@pM is serialized as file://[7f:d:ee9e::7a:828e:c]/-861%**25**A3+/F3&m/@pM on server by XmlMediaTypeFormatter(Notice 25(bolded) added to the url). This works fine when using Json formatter.

Here is my client code
HttpClient client = new HttpClient();
Uri myUri = new Uri("//[07f:d:EE9e::7a:828E:C]/-861%A3+/F3&m/@pM", UriKind.Absolute);

HttpRequestMessage request = new HttpRequestMessage()
{
Content = new ObjectContent<Uri>(myUri, new XmlMediaTypeFormatter()),
RequestUri = new Uri(baseAddress + "/My/EchoUriFromBody"),
Method = new HttpMethod("Post"),
};
var response = client.SendAsync(request).Result;
var myResult = response.Content.ReadAsAsync<Uri>(new List<MediaTypeFormatter>(){new XmlMediaTypeFormatter()}).Result;

Controller code
public class MyController : ApiController
{
[AcceptVerbs("PUT", "POST", "DELETE")]
public Task<Uri> EchoUriFromBody([FromBody]Uri input)
{
var task = Task.Factory.StartNew(() => input);
return task;
}
}

Closed Issue: [Required] should not present users with duplicate errors [590]

$
0
0
See: http://aspnetwebstack.codeplex.com/discussions/396199

The implementation change here is to not recognize the [Required] model validator for reference types when doing the value validation.
Comments: Verified.

Closed Issue: Overly aggressive validation for applying [DataMember(IsRequired=true)] to required properties with value types [270]

$
0
0
With the default route and this controller:
using System.ComponentModel.DataAnnotations;
using System.Web.Http;

namespace ActionSelectionTest.Controllers
{
[FromUri]
public class Test
{
[Required]
public int ID { get; set; }
}

public class ValuesController : ApiController
{
public string Get(Test test)
{
return test.ID.ToString();
}
}
}

And a GET request to api/values/1 you get this error:

{"Message":"An error has occurred.","ExceptionMessage":"Property 'ID' on type 'ActionSelectionTest.Controllers.Test' is invalid. Value-typed properties marked as [Required] must also be marked with [DataMember(IsRequired=true)] to be recognized as required. Consider attributing the declaring type with [DataContract] and the property with [DataMember(IsRequired=true)].","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Validation.Validators.ErrorModelValidator.Validate(ModelMetadata metadata, Object container)\r\n at System.Web.Http.Validation.ModelValidationNode.ValidateThis(HttpActionContext actionContext, ModelValidationNode parentNode)\r\n at System.Web.Http.Validation.ModelValidationNode.Validate(HttpActionContext actionContext, ModelValidationNode parentNode)\r\n at System.Web.Http.Validation.ModelValidationNode.ValidateChildren(HttpActionContext actionContext)\r\n at System.Web.Http.Validation.ModelValidationNode.Validate(HttpActionContext actionContext, ModelValidationNode parentNode)\r\n at System.Web.Http.ModelBinding.Binders.CompositeModelBinder.BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)\r\n at System.Web.Http.ModelBinding.ModelBinderParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder)\r\n at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)"}

Expected result:

We shouldn’t need to require data contract attributes for FromUri types. We should only require the data contract attributes when our formatters that require them are in use.

Workaround:

Remove the validation logic in your config:

config.Services.RemoveAll(
typeof(System.Web.Http.Validation.ModelValidatorProvider),
v => v is InvalidModelValidatorProvider);

Comments: Verified.

Edited Issue: PushstreamContent in Win8 App is not working [324]

$
0
0
I am hitting an issue with using PushStreamContent in the Windows store app. I don’t see the same issue in the traditional console app though.

It’s a simple scenario where I am ‘POST’ing some small data to a service using PushStreamContent as below.

HttpClient client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://.../SimpleMvcWebAPIApplication/api/values");
request.Content = new PushStreamContent((stream, httpContent, transportContext) =>
{
using (var streamWriter = new StreamWriter(stream))
{
string data = "\"hello world\"";
streamWriter.Write(data);
streamWriter.Flush();
}
}, "application/json");

var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

It fails as below.

System.ObjectDisposedException was unhandled by user code
HResult=-2146232798
Message=Cannot access a closed Stream.
Source=mscorlib
ObjectName=""
StackTrace:
at System.IO.__Error.StreamIsClosed()
at System.IO.MemoryStream.Seek(Int64 offset, SeekOrigin loc)
at System.Net.Http.HttpContent.<>c__DisplayClassf.<LoadIntoBufferAsync>b__d(Task copyTask)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at App5.App.<SimpleWebAPIService_Write_Temp1>d__f.MoveNext() in c:\personal\maying\WinRT\client\WinRTClient\App.xaml.cs:line 368
InnerException:

Commented Issue: PushstreamContent in Win8 App is not working [324]

$
0
0
I am hitting an issue with using PushStreamContent in the Windows store app. I don’t see the same issue in the traditional console app though.

It’s a simple scenario where I am ‘POST’ing some small data to a service using PushStreamContent as below.

HttpClient client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://.../SimpleMvcWebAPIApplication/api/values");
request.Content = new PushStreamContent((stream, httpContent, transportContext) =>
{
using (var streamWriter = new StreamWriter(stream))
{
string data = "\"hello world\"";
streamWriter.Write(data);
streamWriter.Flush();
}
}, "application/json");

var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

It fails as below.

System.ObjectDisposedException was unhandled by user code
HResult=-2146232798
Message=Cannot access a closed Stream.
Source=mscorlib
ObjectName=""
StackTrace:
at System.IO.__Error.StreamIsClosed()
at System.IO.MemoryStream.Seek(Int64 offset, SeekOrigin loc)
at System.Net.Http.HttpContent.<>c__DisplayClassf.<LoadIntoBufferAsync>b__d(Task copyTask)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at App5.App.<SimpleWebAPIService_Write_Temp1>d__f.MoveNext() in c:\personal\maying\WinRT\client\WinRTClient\App.xaml.cs:line 368
InnerException:

Comments: I do not agree with the resolution. We need to indeed close the stream to signal pushstreamcontent that we are done writing to the stream. Also, this same piece of code works in a regular console application which indicates that the code is fine. I was able to repro this issue in a windows store app.

Closed Issue: DefaultODataActionProvider error messages [466]

$
0
0
Need to add code to insure ActionName == "" produces meaningful error messages.
One option is to move from using ActionName to full request URL in the error.

Comments: Verified.

Edited Issue: Expose the default logic of link generation to enable re-using logic. [536]

$
0
0
I agree that its easy to create links ourselves, but its natural and easier to just fallback to the default logic too.

Scenarios:
a. I would like to build a 'Transient' action on Product called "ExtendSupportDate". In my HasActionLink logic, I check to see if the given entity instance context(Product) is discontinued or not. if discontinued, i do not want to 'advertise' the action "ExtendSupportDate" otherwise I would like to re-use whatever logic the default Action link convention generates.
b. Similar as above, a scenario where you don't want to show Edit link for some entity instances and for the rest of them would want to use the default Edit link convention that we have.

Currently for scenario 'a', i am doing the following:
----------------------------------------------------------
static IEdmModel GetImplicitEdmModel()
{
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
var products = modelBuilder.EntitySet<Product>("Products");
var productFamilies = modelBuilder.EntitySet<ProductFamily>("ProductFamilies");
var suppliers = modelBuilder.EntitySet<Supplier>("Suppliers");

var config = products.EntityType.TransientAction("ExtendSupportDate");
config.Parameter<DateTime>("newDate");
config.ReturnsFromEntitySet<Product>("Products");
config.HasActionLink(eic =>
{
//Do not advertise 'ExtendSupportDate' for discontinued products
if(eic.EntityType.Name == "DiscontinuedProduct")
return null;

//Advertise for the rest of them
Product pd = (Product)eic.EntityInstance;

return new Uri(eic.UrlHelper.Link(ODataRouteNames.InvokeBoundAction, new {
controller = eic.EntitySet.Name,
boundId = pd.ID,
odataAction = "ExtendSupportDate" }));
});

return modelBuilder.GetEdmModel();
}

Commented Issue: Expose the default logic of link generation to enable re-using logic. [536]

$
0
0
I agree that its easy to create links ourselves, but its natural and easier to just fallback to the default logic too.

Scenarios:
a. I would like to build a 'Transient' action on Product called "ExtendSupportDate". In my HasActionLink logic, I check to see if the given entity instance context(Product) is discontinued or not. if discontinued, i do not want to 'advertise' the action "ExtendSupportDate" otherwise I would like to re-use whatever logic the default Action link convention generates.
b. Similar as above, a scenario where you don't want to show Edit link for some entity instances and for the rest of them would want to use the default Edit link convention that we have.

Currently for scenario 'a', i am doing the following:
----------------------------------------------------------
static IEdmModel GetImplicitEdmModel()
{
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
var products = modelBuilder.EntitySet<Product>("Products");
var productFamilies = modelBuilder.EntitySet<ProductFamily>("ProductFamilies");
var suppliers = modelBuilder.EntitySet<Supplier>("Suppliers");

var config = products.EntityType.TransientAction("ExtendSupportDate");
config.Parameter<DateTime>("newDate");
config.ReturnsFromEntitySet<Product>("Products");
config.HasActionLink(eic =>
{
//Do not advertise 'ExtendSupportDate' for discontinued products
if(eic.EntityType.Name == "DiscontinuedProduct")
return null;

//Advertise for the rest of them
Product pd = (Product)eic.EntityInstance;

return new Uri(eic.UrlHelper.Link(ODataRouteNames.InvokeBoundAction, new {
controller = eic.EntitySet.Name,
boundId = pd.ID,
odataAction = "ExtendSupportDate" }));
});

return modelBuilder.GetEdmModel();
}
Comments: I see that we have helpers for GenerateSelfLink and GenerateNavigationLink, but not for generating action links...was this on purpose...did you mean to one could first call GenerateSelfLink and then just append the action name in the end?

Closed Issue: Implement IODataUrlResolver so that ODataLib can resolve Url references that are part of a batch request [1032]

$
0
0
When doing the following batch request with DataServicesClient:

```
GeneratedDataServicesClient client = new GeneratedDataServicesClient(serviceUrl);
client.Format.UseJson();
BatchCustomer customer = client.BatchCustomer.ToList().First();
Order order = new Order() { Id = 0, PurchaseDate = DateTime.Now };
client.AddToOrder(order);
client.AddLink(customer, "Orders", order);
client.SaveChanges(SaveChangesOptions.Batch);
```

that translates into the following HTTP request:

```
POST BaseUrl/$batch HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: multipart/mixed; boundary=batch_77c46244-d02f-4714-9e8d-28dd0910189c
Accept: multipart/mixed
Accept-Charset: UTF-8
User-Agent: Microsoft ADO.NET Data Services
Host: host
Content-Length: 1099
Expect: 100-continue

--batch_77c46244-d02f-4714-9e8d-28dd0910189c
Content-Type: multipart/mixed; boundary=changeset_d758f8a5-20a0-4d01-8c33-0884b8202729

--changeset_d758f8a5-20a0-4d01-8c33-0884b8202729
Content-Type: application/http
Content-Transfer-Encoding: binary

POST BaseUrl/Order HTTP/1.1
Content-ID: 11
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8

{"Id":0,"PurchaseDate":"2013-05-06T09:05:44.6392992-07:00"}
--changeset_d758f8a5-20a0-4d01-8c33-0884b8202729
Content-Type: application/http
Content-Transfer-Encoding: binary

POST BaseUrl/BatchCustomer(0)/$links/Orders HTTP/1.1
Content-ID: 12
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
Content-Type: application/json;odata=minimalmetadata

{"url":"$11"}
--changeset_d758f8a5-20a0-4d01-8c33-0884b8202729--
--batch_77c46244-d02f-4714-9e8d-28dd0910189c--
```

The request fails because the $11 reference in the second request of the batch doesn't get resolved properly. The root of the problem is that ODataLib is not able to resolve the Url. In order for ODataLib to be able to properly resolve the Url we need to implement IODataUrlResolver in the ODataMessageWrapper class.

Closed Issue: OData $batch sends the wrong response when a request within a changeset fails [1033]

$
0
0
Given a $batch request like the following, where the second operation in the changeset fails as this one

```
POST http://jcalvarro-wsr3:9001/batch/$batch HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: multipart/mixed; boundary=batch_e4243eef-ba43-49da-8dfb-a006d9e918f2
Accept: multipart/mixed
Accept-Charset: UTF-8
User-Agent: Microsoft ADO.NET Data Services
Host: jcalvarro-wsr3:9001
Content-Length: 1076
Expect: 100-continue
Connection: Keep-Alive

--batch_e4243eef-ba43-49da-8dfb-a006d9e918f2
Content-Type: multipart/mixed; boundary=changeset_6bb58eec-2717-4673-b074-919584c38eea

--changeset_6bb58eec-2717-4673-b074-919584c38eea
Content-Type: application/http
Content-Transfer-Encoding: binary

POST http://jcalvarro-wsr3:9001/batch/BatchCustomer HTTP/1.1
Content-ID: 1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8

{"Id":10,"Name":"Customer 10"}
--changeset_6bb58eec-2717-4673-b074-919584c38eea
Content-Type: application/http
Content-Transfer-Encoding: binary

POST http://jcalvarro-wsr3:9001/batch/BatchCustomer HTTP/1.1
Content-ID: 2
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8

{"Id":-1,"Name":"Customer -1"}
--changeset_6bb58eec-2717-4673-b074-919584c38eea--
--batch_e4243eef-ba43-49da-8dfb-a006d9e918f2--
```

the current response is the following

```

HTTP/1.1 202 Accepted
Content-Length: 886
Content-Type: multipart/mixed; boundary=batchresponse_47b1b595-6669-4b92-8cc9-eee0cba4517f
Server: Microsoft-HTTPAPI/2.0
DataServiceVersion: 3.0
Date: Mon, 06 May 2013 20:52:22 GMT

--batchresponse_47b1b595-6669-4b92-8cc9-eee0cba4517f
Content-Type: multipart/mixed; boundary=changesetresponse_138912bb-52f3-4731-ae06-013e250ca45f

--changesetresponse_138912bb-52f3-4731-ae06-013e250ca45f
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 201 Created
Location: http://jcalvarro-wsr3:9001/batch/BatchCustomer(10)
Content-ID: 1
Content-Type: application/json; odata=minimalmetadata; charset=utf-8
DataServiceVersion: 3.0

{
"odata.metadata":"http://jcalvarro-wsr3:9001/batch/$metadata#BatchCustomer/@Element","Id":10,"Name":"Customer 10"
}
--changesetresponse_138912bb-52f3-4731-ae06-013e250ca45f
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 400 Bad Request
Content-ID: 2


--changesetresponse_138912bb-52f3-4731-ae06-013e250ca45f--
--batchresponse_47b1b595-6669-4b92-8cc9-eee0cba4517f--
```

and according to the OData spec, it should be as follows:

Structurally, a batch response body MUST match one-to-one with the corresponding batch request body, such that the same multipart MIME message structure defined for requests is used for responses.
The exception to this rule is that when a request within a Change Set fails, the Change Set response is not represented using the multipart/mixed media type.
Instead, a single response, using the “application/http” media type and a Content-Transfer-Encoding header with a value of “binary”,
is returned that applies to all requests in the Change Set and MUST be formatted according to the Error Handling section of [OData:Core].

New Post: Navigation Property - problem with the metadata

$
0
0
hi
in out project we are using
ODataModelBuilder builder = new ODataModelBuilder();

            builder.Namespace = "Stabilis.Situator.OpServerTypes";

            EntitySetConfiguration<Incident> incident = builder.EntitySet<Incident>("Incidents");
            incident.EntityType.HasKey(c => c.IncidentID);
            incident.EntityType.Property(c => c.Name);
            incident.EntityType.Property(c => c.IncidentType);
            incident.EntityType.Property(c => c.Description);
            incident.HasIdLink(eic =>
            {
                return eic.GenerateSelfLink(false);
            }, false);

            var hasManyComments = incident.EntityType.HasMany(c => c.IncidentComments);
            incident.HasNavigationPropertyLink(hasManyComments, (z, y) =>
            {
                return z.GenerateNavigationPropertyLink(y, false);
            }, false);

            EntitySetConfiguration<IncidentComment> incidentComment = builder.EntitySet<IncidentComment>("IncidentComments");
            incidentComment.EntityType.HasKey(c => c.CommentID);
            incidentComment.EntityType.Property(c => c.IncidentID);
            incidentComment.EntityType.Property(c => c.Content);
            incidentComment.HasIdLink(eic =>
            {
                return eic.GenerateSelfLink(false);
            }, false);
i have tested it against BreezeJS and also wcf data client on both i am not getting the IncidentComments - i am getting empty collection, but with sniffer i can see that this data is transferred, so i can guess that it is related to the metadata

<EntityType Name="Incident">
<Key>
<PropertyRef Name="IncidentID"/>
</Key>
<Property Name="IncidentID" Type="Edm.Int32" Nullable="false"/>
<Property Name="Name" Type="Edm.String"/>
<Property Name="IncidentType" Type="Edm.Int32" Nullable="false"/>
<Property Name="Description" Type="Edm.String"/>
<NavigationProperty Name="IncidentComments" Relationship="Stabilis.Situator.OpServerTypes.Stabilis_Situator_OpServerTypes_Incident_IncidentComments_Stabilis_Situator_OpServerTypes_IncidentComment_IncidentCommentsPartner" ToRole="IncidentComments" FromRole="IncidentCommentsPartner"/>
</EntityType>
<EntityType Name="IncidentComment">
<Key>
<PropertyRef Name="CommentID"/>
</Key>
<Property Name="CommentID" Type="Edm.Int32" Nullable="false"/>
<Property Name="IncidentID" Type="Edm.Int32" Nullable="false"/>
<Property Name="Content" Type="Edm.String"/>
</EntityType>

<Association Name="Stabilis_Situator_OpServerTypes_Incident_IncidentComments_Stabilis_Situator_OpServerTypes_IncidentComment_IncidentCommentsPartner">
<End Type="Stabilis.Situator.OpServerTypes.IncidentComment" Role="IncidentComments" Multiplicity="*"/>
<End Type="Stabilis.Situator.OpServerTypes.Incident" Role="IncidentCommentsPartner" Multiplicity="0..1"/>
</Association>
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Incidents" EntityType="Stabilis.Situator.OpServerTypes.Incident"/>
<EntitySet Name="IncidentComments" EntityType="Stabilis.Situator.OpServerTypes.IncidentComment"/>
<EntitySet Name="ExtendedProperties" EntityType="Stabilis.Situator.OpServerTypes.IncidentExtendedProperty"/>
<EntitySet Name="Deployments" EntityType="Stabilis.Situator.OpServerTypes.Deployment"/>
<EntitySet Name="DTasks" EntityType="Stabilis.Situator.OpServerTypes.DTask"/>
<EntitySet Name="DTaskComments" EntityType="Stabilis.Situator.OpServerTypes.DTaskComment"/>
<EntitySet Name="DTaskEvents" EntityType="Stabilis.Situator.OpServerTypes.DTaskEvent"/>
<EntitySet Name="Assets" EntityType="Stabilis.Situator.OpServerTypes.Asset"/>
<AssociationSet Name="Stabilis_Situator_OpServerTypes_Incident_IncidentComments_Stabilis_Situator_OpServerTypes_IncidentComment_IncidentCommentsPartnerSet" Association="Stabilis.Situator.OpServerTypes.Stabilis_Situator_OpServerTypes_Incident_IncidentComments_Stabilis_Situator_OpServerTypes_IncidentComment_IncidentCommentsPartner">
<End Role="IncidentCommentsPartner" EntitySet="Incidents"/>
<End Role="IncidentComments" EntitySet="IncidentComments"/>
</AssociationSet>
</EntityContainer>

New Post: Call WebAPI from MVC View

$
0
0
Eilon,

I have been working around this, as I'm not very happy with the idea of creating multiple local HTTP requests for each request to my app.

Is this something in the roadmap? Is this being considered for the neat future?
Looks like a basic functionality that MVC had since the beggining, but there is no simple way to do this with WebAPI.

Thanks.

Reviewed: v4.0 RTM (五月 26, 2013)

$
0
0
Rated 2 Stars (out of 5) - adefwfdddddddddddddddddddddddddddddd

New Post: CovariantModelBinder submission

$
0
0
Hi,

I think that it could be a great stuff ! During my development, this binder could help me a lot ! There is often different way to do but i think that CovariantModelBinder could help to do the right way

Let me know if you link some examples ...

Reviewed: v4.0 RTM (五月 26, 2013)

$
0
0
Rated 5 Stars (out of 5) - I like it,It's very good

New Post: Web API OData 5.0 alpha ETA?

$
0
0
I see there was a nuget release of the WebApi 5.0 alpha last week. Sadly, i can't update to it because of the version dependency for Web API OData specifically disallows anything >= 4.1.

Is there an ETA on when there will be alpha packages for the other bits of the webstack?

Thanks,
Michael.

Created Unassigned: Make non-generic TryUpdateModel methods [1071]

$
0
0
Sometimes it is necessary to make a polymorphic binding of model on the basis of the interface. But if one pass the model of a particular type, wich implements the necessary interface, the binding doesn't occur because the TryUpdateMethod method is generic. Make overloads, where only the object model would be transfered to the entrance of the method:

bool TryUpdateModel(object model)
bool TryUpdateModel(object model, string prefix)

etc.

Example of usage:

```
public ActionResult Process(SomeDescriminatorEnum someDescriminator)
{
IMyModel model = GetConcreteForm(someDescriminator);
if (TryUpdateModel(model))
{
// ...
}
// ...
}
```

Commented Unassigned: Add overloads taking a CancellationToken parameter [983]

$
0
0
Currently some of TAP-based methods in the aspnetwebstack libraries does not have overloads with _CancellationToken_ parameter. For instance following classes:

_System.Net.Http_: HttpContent and successors.
```
HttpContent: ReadAsStringAsync, ReadAsByteArrayAsync, ReadAsStreamAsync, etc.
```
_System.Net.Http.Formatting_: HttpContent extensions.
```
HttpContentMessageExtensions: ReadAsHttpRequestMessageAsync
HttpContentMultipartExtensions: ReadAsMultipartAsync
HttpContentFormDataExtensions: ReadAsFormDataAsync
HttpContentMessageExtensions: ReadAsHttpRequestMessageAsync
MultipartStreamProvider: ExecutePostProcessingAsync
```
_System.Net.Http.Formatting_: MediaTypeFormatter and successors.
```
MediaTypeFormatter: ReadFromStreamAsync, WriteToStreamAsync
BufferedMediaTypeFormatter
FormUrlEncodedMediaTypeFormatter
JsonMediaTypeFormatter
XmlMediaTypeFormatter
```
_System.Web.Http_: Model binder which breaks cancellable pipeline.
```
FormatterParameterBinding: ReadContentAsync
```
Methods of above classes potentially may be executed for a long time period. In addition if we're trying to create custom _MediaTypeFormatter_ we unable to cancel _ReadFromStreamAsync_ and _WriteToStreamAsync_ methods.

I suppose that it will be great if such methods will contain an overloads with a _CancellationToken_ parameter, which should be properly integrated into Web API message processing pipeline.

Code sample how it can be refactored: https://aspnetwebstack.codeplex.com/SourceControl/network/forks/dtretyakov/CancellationToken/contribution/4472

P.S. Discussions looks dead - no answers for over 2 weeks: http://aspnetwebstack.codeplex.com/discussions/438601
Comments: I agree, it is needed to add such feature. In our case, we're using ReadAsMultipartAsync() for stream-based upload of large files and had to throw OperationCancelledException() in our Stream wrapper, that contains cancellation checking logic and checks property called CancelPending of the associated I/O descriptor class in overridden Read/Write methods. if a client wants to cancel upload request (via AJAX), then I/O descriptor's property CancelPending is set to true and whenever parser's Task calls Read/Write method on the Stream, this property is being checked before calling underlying stream's methods. The exception, that is thrown in Read/Write methods causes Task returned by ReadAsMultipartAsync() to stop further processing that is being indicated by Task.IsFaulted in the MVC controller and check Task's Error property. Nevertheless, this is not so clean, but the only way for us how to indirectly stop the upload processing task whose "Cancel" is initiated from the server's side upon receiving client's cancel request. The advantage in our case is, that we can insert our cancellation logic layer via Stream wrapper class into the MIME multipart upload parser, which gets stream by calling GetStream() method from the passed MultipartStreamProvider. However, in other cases where injecting own cancellation logic is impossible, the cancellation token support in the cases you mentioned is really welcome.

Edited Unassigned: MVC: Make non-generic TryUpdateModel methods [1071]

$
0
0
Sometimes it is necessary to make a polymorphic binding of model on the basis of the interface. But if one pass the model of a particular type, wich implements the necessary interface, the binding doesn't occur because the TryUpdateMethod method is generic. Make overloads, where only the object model would be transfered to the entrance of the method:

bool TryUpdateModel(object model)
bool TryUpdateModel(object model, string prefix)

etc.

Example of usage:

```
public ActionResult Process(SomeDescriminatorEnum someDescriminator)
{
IMyModel model = GetConcreteForm(someDescriminator);
if (TryUpdateModel(model))
{
// ...
}
// ...
}
```

New Post: Odata batch issue - with nightly

Viewing all 7925 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>