C# - Why Is System.Data.Services.MimeTypeAttribute Now Only A Class Level Attribute

Apr 7, 2010

I'm getting started with Astoria/ADO.NET Data Services/WCF Data Services. Looking through a lot of the code samples out there, it appears that the MimeType attribute used to be a method level attribute. After installing the latest update, it is now a class level attribute.

If I have more than one Service Operation that I want to return as a certain MimeType, then it appears now that I have to create a new service for each operation. Is this correct?

Most examples are like this:

[WebGet]
[SingleResult]
[MimeType("application/pdf")]
public IQueryable<byte[]> FooPDF()
{
var result = from p in this.CurrentDataSource.MyPDFs
where p.FooID == 2
select p;
return result.Take(1).Select(p => p.PDF);
}

I get "Attribute 'MimeType' is not valid on this declaration type. It is only valid on 'class' declarations." when I compile, because now I can't do this.

Now, I have to do this:

[MimeType("FooPDF", "application/pdf")]
public class FooService : DataService<FooDBEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetServiceOperationAccessRule("FooPDF", ServiceOperationRights.All);
}
[WebGet]
[SingleResult]
public IQueryable<byte[]> FooPDF()
{
var result = from p in this.CurrentDataSource.MyPDFs
where p.FooID == 2
select p;
return result.Take(1).Select(p => p.PDF);
}
}

What's worse is that I can't add duplicate MimeType attributes to my class.

View 1 Replies


Similar Messages:

WCF / ASMX :: Only Web Services With A [ScriptService] Attribute On The Class Definition Can Be Called From Scr...

Nov 4, 2010

I have created a web service. When I check the service directly from it's web page it works correctly. Here's what the code looks like:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Configuration;
using System.Runtime.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using Microsoft.SharePoint;
using System.Collections;
namespace MDA.WebParts.SPRolodex_Web_Service
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class SPRolodex_Web_Service : System.Web.Services.WebService
{
public SPRolodex_Web_Service()
{
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool ListExists(string personalUrl, string listName)
{
try
{
SPSite mySite = new SPSite(personalUrl);
SPWeb web = mySite.OpenWeb();
SPList list = web.Lists[listName];
return true;
}
catch (ArgumentException)
{
return false;
}
}
}
}

However, when I call the method using ServiceProxy.js (a jQuery based library) I get this error

"Only Web services with a [ScriptService] attribute on the class definition can be called from script."

As you can see the class has the ScriptService attribute and the methods have the ServiceMethod attribute.

View 1 Replies

Does Anyone Know A Good Practice To Use When Developing For The System.directory Services Class

Jan 31, 2011

I'm trying to create a data access later using System.DirectoryServices. I'd like to use the MVC 2 framework and have all my views be mostly strongly-typed. Does anyone know any good way to this?

For example I started creating a Group Entity:

public class Group
{
public string DistinguishedName { get; set; }
public string GroupName { get; set; }
}

And an abstract interface:

public interface IGroupRepository
{
List<Group> Groups { get; }
}

I am confused about developing the GroupRepository using the system.directory services. Connecting to a SQL database is easy there are examples everywhere but I have no been able to find any using the System.directory sevices in conjunction with a class using MVC. Has anyone tried to do something like this?

View 1 Replies

MVC Generic Base View Class / Error Parsing Attribute 'something': Type 'System.Web.Mvc.ViewPage'

Feb 5, 2010

I can have a base class for views in an MVC project like this:

public class BaseViewPage : System.Web.Mvc.ViewPage
{
public string Something { get; set; }
}

And then in the ASPX I can do this:

<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage" %>

This works fine; the problem is when I try to do the same with the generic version:

public class BaseViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class
{
public string Something { get; set; }
}

When I try to use this from the ASPX, like this:

<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage<SomeClass>" %>

I get the error message:

Error parsing attribute 'something': Type 'System.Web.Mvc.ViewPage' does not have a public property named 'something'.

Notice how it tries to use System.Web.Mvc.ViewPage rather than my BaseViewPage class. To make it more interesting, if I remove the "Something" attribute from the Page directive and put some code in the generic version of BaseViewPage (OnInit for example) the class is actually called / used / instantiated.

So, am I doing something wrong or is this a limitation.

View 1 Replies

WCF / ASMX :: Web Service To Inherit From A Custom Base Class That Inherits System.Web.Services.WebMethod Inste...

Oct 18, 2010

Recently, I tried to get my Web Service class to inherit from a custom base class that inherits from System.Web.Services.WebMethod instead of the System.Web.Services.WebMethod directly.

However, I've been getting Error 500.

Public Class Service1
Inherits BaseClass
<System.Web.Services.WebMethod()> _
Public Function GetSessionID() As String
GetSessionID = Me.Session.SessionID
End Function
End Class

public class BaseClass
Inherits System.Web.Services.WebService
public property Property1 as string
public property Property2 as string

End Class

View 6 Replies

MVC Class Level Custom Data-annotation And ModelState Keys?

Apr 10, 2010

I have custom class level validation attribute, inheriting from ValidationAttribute, on my model.

How come it doesn't register a key in the ModelState when its IsValid is false? I can see the the error message in the ModelState.Values collection, but the ModelState.Keys collection only shows an empty string "". Can I provide a key for it - presumably this is because its not assigned to a property?

I wanna be able to use ModelState.Remove in my controller to remove this error upon a certain condition, but I have no Key!

View 1 Replies

Configuration :: Error: The Current Trust Level Does Not Allow Use Of The 'AspCompat' Attribute

Aug 25, 2010

<%@ Page Language="VB" MasterPageFile="~/template.admin.master" AspCompat ="true" AutoEventWireup="false" CodeFile="AddNewResumes.aspx.vb" Inherits="AddNewResumes" title="Sarian solutions - Add New Resume" %>

total website with this page runnig in the local system. but when i put in online system it giving error like

Parse Error:The current trust level does not allow use of the 'AspCompat' attribute

View 9 Replies

Web Services - Can A Webservice Class Inherit Page Class?

Jan 6, 2011

i have an application consisting of two asp.net projects. And i have have a BasePage which inherits System.Web.UI.Page and have the class some core logic which i require in all of my pages(Implemented in BasePage.cs). So all my pages inherit this BasePage.cs . Now can an Webservice inherit the same class apart from the normal webservice class System.Web.Services.WebService

View 4 Replies

To Add A Class To An Existing Class Attribute Of Object Via C#?

Jul 20, 2010

I have an existing class for an input, is it possible to add an additional class for the object in C#.net, instead of doing a if/else and not having a preset class on the object in the first place?

View 3 Replies

Web Forms :: Class-level Variable Loses It's Value?

Jun 22, 2010

Google usually solves my problems for me, but this one has me stumped. I have a page with the following code, in which lstPayments is a listview control:

public partial class frmPerson : System.Web.UI.Page
{
protected bool paymentWarning = false;
protected void Page_PreRender(object sender, EventArgs e)
{
if (paymentWarning == true)
{
string alertText = "alert('Hello World');";
if (!ClientScript.IsStartupScriptRegistered("Alerter"))
ClientScript.RegisterStartupScript(this.GetType(), "Alerter", alertText, true);
}
}
protected void lstPayments_ItemInserted(object sender, ListViewInsertedEventArgs e)
{
paymentWarning = true;
}
}

As you can see, I'm trying to get an alert box displayed after a new payment is entered. As I expect, lstPayments_ItemInserted is executed first, and paymentWarning is duly set to true. However, when Page_PreRender subsequently executes, paymentWarning has been re-initialised: it's false again!

The only way I can get the class-level variable paymentWarning to retain it's value between the two event handlers is to declare it static, which I don't want to do for obvious reasons. There must be something I am failing to understand about how class-level variables work in aspx pages.

View 4 Replies

C# - Setting Class-Level Variable To Use Between Event Handlers?

Mar 17, 2010

I'm having a hard time understanding why the following code doesn't work. I'm sure it's something remedial that I'm missing or not understanding. I currently have a page that asks for user input. If, based on the input and logged in user, I find data from this page already in the database, I need to update the existing records rather than creating new ones, so I set a class-level bool to true. The problem is, when MyNextButton is clicked, PreviouslySubmitted is still false. So, I'm not sure how to make the value of this variable persist.

public partial class MyForm : System.Web.UI.Page
{
private bool PreviouslySubmitted;
protected void Page_Load(object sender, EventArgs e)
{
MyButton.Click +=
(o, i) =>
{
q = from a in db.TableA
where (a.SomeField == SomeValue)
select a;
if(q.Any())
{
PreviouslySubmitted = true;
//populate the form's fields with values from database for user to revise
}
}
MyNextButton.Click +=
(o, i) =>
{
//the value of PreviouslySubmitted is false at this point,
//even if I made sure it was set to true the previous postback
if(PreviouslySubmitted)
{
//update database
}
else
{
//insert into database
}
}

View 2 Replies

Web Forms :: Use System.Drawing.Bitmap Class Into Other Class?

Oct 5, 2010

How can I to use System.Drawing.Bitmap class into athoer class?

using System.Data;
using System.Collections;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace University
{
public class Class1
{
System.Drawing.Bitmap BMP=new System.Drawing .Bitmap();
}
}

when I use System.Drawing.Bitmap gives error this class does not exists

View 2 Replies

What Is The Class Attribute And How To Use

Nov 8, 2010

What is the class attribute and how to use

View 1 Replies

Architecture :: Is Using Class Level Private Shared Variables Not Good

May 28, 2010

In page behind classes I am using a private and shared object (list<client> or just client) to temporary hold data coming from database or class library. This object is used temporarily to catch data and than to return, pass to some function or binding acontrol. 1st: Can this approach harm any way ? I couldnt analyse it but a thought was using such shared variables may replace data in it ?2nd: Please comment also on using such variables in BLL (to hold data coming from database) where new object of BLL class will be made everytime.

[Code]....

View 4 Replies

C# - Is Using Private Shared Objects/variables On Class Level Harmful

May 28, 2010

In page behind classes I am using a private and shared object and variables (list or just client or simplay int id) to temporary hold data coming from database or class library. This object is used temporarily to catch data and than to return, pass to some function or binding a control.1st: Can this approach harm any way ? I couldn't analyze it but a thought was using such shared variables may replace data in it when multiple users may be sending request at a time?

[code]...

View 2 Replies

ADO.NET :: Class 'system.data.datatable' Cannot Be Indexed Because It Has No Default Property

Dec 17, 2010

I'm trying to get a custommembership to work and i have the following problem.

i get a error class 'system.data.datatable' cannot be indexed because it has no default propert.

Here's my function.

Public Overrides Function GetUserNameByEmail(ByVal userEmail As String) _
As String
Dim userName As String = ""
Try
Dim mymember As New Data.DataTable

[code].....

View 4 Replies

Web Forms :: Reference Control On Third Level Master Page From Content Base Class?

Aug 8, 2010

I am attempting to access a textbox control on a master page from a code behind base class but having problems. I have 3 levels of master pages. m1.master is the master page for m2.master which is the master page for m3.master.m3.master has a textbox as shown below

<%Master
Language="C#"
MasterPageFile="~/m2.master"
AutoEventWireup="true"
CodeFile="M3.master.cs"
Inherits="M3"
%>
<asp:Content
ID="Content5"
ContentPlaceHolderID="M2"
Runat="Server">
<asp:TextBox
ID="text1"
runat="server"
></asp:TextBox>
<asp:ContentPlaceHolder
ID="M3"
runat="Server"></asp:ContentPlaceHolder>
</asp:Content>

I have a content page c1.aspx that uses m3.master as its master page as shown below:

@
Page
Title=""
Language="C#"
MasterPageFile="~/m3.master"
AutoEventWireup="true"
CodeFile="c1.aspx.cs"
Inherits="_c1".................

View 2 Replies

Alternative For Static Method In Interface - Enforce Implementing Class-level Methods

Oct 28, 2010

I have a hierarchy in my website project as below:

[CustomControl1 - folder]
- CustomControl1.ascx
- CustomControl1.css
- CustomControl1.js

I load css and js files dynamicaly based on which controls are used on particular page. I am doing it by using following code:

[code]....

where AddLinks method adds HtmlLink controls to Page.Header with href attribute set to coresponding css and/or js file.

I would like to add Interface that would force new controls to have AddLinks method but it is impossible since it is a static method. Because my custom controls inherit from Control class I cannot use abstract class and/or virtual methods either. How can I achieve my goal?

View 1 Replies

How To Use The Webservice Attribute System.ComponentModel.ToolboxItem(false)

Mar 22, 2011

When should we add this attribute to an asp.net webservice ?

[System.ComponentModel.ToolboxItem(false)]

View 1 Replies

ADO.NET :: Class 'System.Data.SqlClient.SqlDataAdapter' Cannot Be Indexed Because It Has No Default Property?

Feb 22, 2011

First time using a dataset instead of a data reader, and I'm trying to fill both a datalist on my page, and set the selected item value for a drop down list. The datalist on the page is displaying properly, but I get this errorClass 'System.Data.SqlClient.SqlDataAdapter' cannot be indexed because it has no default property. when trying to set the selected value for the drop down list. Why can't I get the selected value for the drop down list to work properly?

[Code]....

View 3 Replies

Starting Or Stopping Windows Services In A Remote System?

Mar 1, 2011

how to start or stop windows services present in a remote system using Servicecontroller in c#.net.

View 1 Replies

Getting System.Web.Script.Services.ScriptService Is Not Defined Error?

Jan 19, 2011

I created a small new webservice for AutoCompleteExtender and for some reason I am getting "type System.Web.Script.Services.ScriptService is not defined" error. I Googled this and found a few threads about similar issues but was unable to resolve mine. Here is the example of the code:

[Code]....

When I add Imports System.Web.Script.Services I get "Namespace or type specified in the Imports 'System.Web.Script.Services' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases".

I've tried adding Reference to System.Web.Extensions and it didn't do anything. What could be the problem?

View 2 Replies

C# - Access Parent Class From Custom Attribute?

Jun 6, 2010

Is it possible to access a parent class from within an attribute.

For example I would like to create a DropDownListAttribute which can be applied to a property of a viewmodel class in MVC and then create a drop down list from an editor template. I am following a similar line as Kazi Manzur Rashid here.

He adds the collection of categories into viewdata and retrieves them using the key supplied to the attribute.

I would like to do something like the below,

public ExampleDropDownViewModel {
public IEnumerable<SelectListItem> Categories {get;set;}
[DropDownList("Categories")]
public int CategoryID { get;set; }
}

The attribute takes the name of the property containing the collection to bind to. I can't figure out how to access a property on the parent class of the attribute. Does anyone know how to do this?

View 2 Replies

Retrieving Custom Attribute On A Webpage Class

Jan 20, 2010

I've create a custom attribute for my web pages... In the base page class I've created I'm trying to pull if that attribute has been set. Unfortunately it does not come back as part of the GetCustomAttributes function. Only if I explicitly use the typeof(myclass) to create the class. I have a feeling it's due to how asp.net classes are generated.

[Code]....

View 1 Replies

StringTemplate Cannot Render Attribute Of LINQ To SQL Class

Jan 21, 2010

i use GUI tool of vs2008 to generate some LINQ to SQL class, my problem is StringTemplate can not reach attributes of those model

$persons:{
<li>$it.name$</li>
}$

it printed:

<li></li>
<li></li>
<li></li>

name is public property of Person model. If i create a person class by myself, and the same attributes, StringTemplate can get it.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved