Return Serializable Object From FileStream?

Dec 30, 2010

I'm a little green when it comes to streaming and serialization...but what i wanna do is make the Upload method on the server return a serializable object to the client (it is void right now). I have a public class ServiceResult that i decorate with [Serializable], and a public class FileTransferService that implements IFileTransferService

[ServiceContract()]
public interface IFileTransferService
{
[OperationContract(IsOneWay = false)]
string Upload(FileTransferRequest request);
}
The implementation does its thing, and then at the end i create and serialize the object and try to return the string
return ServiceResultSerializer.SerializeAnObject(result);
On the client side i call this service using this class
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IFileTransferService")]
public interface IFileTransferService
{
// CODEGEN: Generating message contract since the wrapper name (FileTransferRequest) of message FileTransferRequest does not match the default value (Upload)
[System.ServiceModel.OperationContractAttribute(IsOneWay = false, Action = "http://tempuri.org/IFileTransferService/Upload")]
string Upload(FileTransferRequest request);
}

I'm basically taking this project found on this blog: [URL] And trying to make it return a value that the client caller can use I get an error right now that says: The operation 'Upload' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters. Which i have no idea what it means :P I think cuz im trying to change the Service paramaters.

View 1 Replies


Similar Messages:

C# - Object Serializable For AJAX - WCF And ViewState

Jun 30, 2010

consider the following class and struct

public class Entity {
public IdType Id {get;set;}
public string Data {get;set;}
}
[TypeConverter(IdTypeConverter))]
public struct IdType {
... any data ...
}

The IdTypeConverter can convert the IdType struct from and to string. Now, what I want is this class to be serializable for AJAX, WCF and ViewState. The senario could be a WCF web service which provides as array of Entity[] to a DataSource. And a custom control which binds to the datasource, saves this class to it's ViewState and sends the data to client side code. This could be achieved easily by simply adding a [Serializable] attribute to all serialized types. But I don't want the IdType to be serialized, but to be converted to a string. Thus the JSON representation should be

{ 'Id'=>'StringRepresentationOfId', 'Data'=>'foo' }

This would analogously be the optimal serialization for WCF and ViewState. Another solution would be to write another class

public class JsonEntity {
public JsonEntity(Entity from) {
Id = from.Id;
Data = from.Data;
}
public string Id {get;set;}
public string Data {get;set;}
}

and use this for JsonSerialization. But I don't like this, because this would imply that the control which is sending the data to the client knows about the Entity type. The actual question is: Is it possible to customize JsonSerialization with attributes without breaking WCF and ViewState serialization? DIT: An answer like "That' impossible" would satify me, since I'd stop trying.

View 2 Replies

FileStream And FileStream Buffer Size To Open A File?

Jan 25, 2010

I've got a vb.net page that when a user clicks a button in a gridview, it copys the file (row seleted) in the gridview as "Label2" from the webserver to the users pc. (We had to setup a lot of security to get it so the webserver could copy to the users pc). I have that all working fine, but now, I'm trying to see if FileStream will then open the file that was just downloaded on the users PC. I'm not familiar with FileStream, and could use a little push in the right direction. (Disclaimer, yes I know downloading the file directly to the pc is a crazy thing to do, but it's a really long story. :-)


For the FileStream portion, I found this sample, but don't quite understand if I can incorporate it into my button click event. Here's the sample [URL]

[Code]....

[Code]....

[Code]....

View 3 Replies

SQL Server :: How To Query Return All Data In Array Object / Collection Object

Sep 14, 2010

how to query return all data in Array Object ,Hash Table ,And DataTable dataRow

View 4 Replies

How To Return Object After Insert

Mar 29, 2011

I am doing a sql INSERT and would like to get a copy of object immediately after insert. Does C# have a command to achieve this??

View 1 Replies

C# - Can Return A Object With Data In It

Aug 11, 2010

I am wanting to get the function below from the file pageDAL.cs to return the object page with the values for whatever pageID I pass in. If I do not need to use a DataSet or DataTable that is fine. What is the best way?

public page getPage(int _pageID)
{
DataTable dt = new DataTable;
using (SqlDataAdapter da = new SqlDataAdapter("select PageID,ParentID,CategoryID,Name,PageHTMLContent,NavigationText,TopMenu,SubMenu,DisplayOrder,Active from Page where PageID = " + _PageID, ConnectionStrings.StaceysCakes))........

View 3 Replies

DataRows Not Serializable In 2.0

Mar 14, 2011

My application uses DataRows and they are not serializable. Is there any workaround for the same?

View 1 Replies

MVC :: Return RedirectToAction() Passing Object?

Apr 9, 2010

I have the following ActionResult() method:

[Code]....

The method is called once the <form> is submitted. If the validation is good, it moves on to create a new user Once the new user is created, I want to redirect the user to a "ThankYou" page passing along the newly created user (object). The TempData["User"] trick seems to work like a charm! Then inside my ThankYou ActionResult() I do the following:

[Code]....

The problem I have is once the user has been redirected to the "ThankYou" page. If he decides to refresh (F5) his browser, the value in the TempData is lost.

What are my possibilities to overcome this issue?

Instead of passing an entire object to my "ThankYou" page, I initially thought of passing the ID of the newly created user and re-query my database to get the object.

The only problem is that the ID will be seen in the QueryString allowing the user to simply change the ID value and try to find other users...

Is my only other alternative to simply place the user object inside a Session? Is that my only other option?

View 6 Replies

C# - Create And Return A DTO For An Object Which Has 10 Attributes?

Dec 2, 2010

1) I want to know what is the recommended way to create & return a DTO for an object which has 10 attributes and I only want to return 2 with my DTO object.

2) Should DTO's have their own namespace ? If yes, how do we organize them ? Each DTO inside a single class file or all DTO's inside a single class ?

View 2 Replies

C# - ObjectDataSource Return Object From Cache?

Jan 13, 2011

Is there any way to return object from Session when Select is called on ObjectDataSource? Specifically, I have Products object and saved in Session. Now on another page I have ObjectDataSource which will call same bussiness object method to get Products object. Here I want to hook up any event like Selecting and I would like to return Products object from Session to Select method of ObjectDataSource.

View 1 Replies

C# - JQuery Ajax WebMethod Return Object

Jan 14, 2011

I have a web Method in my C# that is called via Jquery ajax method. The web method should return an object back to the Jquery which will be used to populate. I have tried returning a JsonResult object, the actual object and nothing seems to work! I'm not using MVC (Unfortunately). Is there a way that I can return an object from my web method which can be used by my AJAX method? here is the link for my JQuery AJAX method [URL]

View 1 Replies

MVC: Return Different Views Depending On Object Type?

Jan 3, 2011

my controller, I'm generically deserializing Xml. The object being deserialized to could end up being any number of different types. This, of course, won't be known at compile time. I've created a number of partial views, each of which are strongly typed to a different object that is a possible outcome of the Xml deserializaton.My problem is that I'm struggling with a good way to return the right view. I could always switch on some property in the object, or use a Key/ViewName Dictionary mapping to get the right view name, but I was hoping for something a little more generic than that.Does anyone know of a way that I could implicitly say, "return the view that is typed off of the object I have."?

View 1 Replies

Return A Json Object In Webforms Programming?

Jun 2, 2010

In ASP.Net MVC action methods can return json objects simply by returning something like so:

JSon([whatever])

How do I return a JSon representation of say List<String> with webforms either through a service or through a method in the code behind of an aspx page? This seems incredibly confusing compared to ASP.Net MVC.

View 3 Replies

C# - Return Linq Query Into Single Object?

Mar 16, 2011

I have this code in my controller:

public ActionResult Details(int id)
{
using (var db = new MatchGamingEntities())

[code]...

View 3 Replies

C# - Check Whether A Instance Is Serializable?

Nov 12, 2010

How can check whether a instance is marked as serializable?

View 4 Replies

Determine Which Classes Are Serializable?

Aug 16, 2010

I am changing my ASP.NET app to use a web farm. To do this, I need to change the session state from in-proc to a State Server. To do this, it is my understanding that the classes that are used must be marked as serializable. How can you tell if that is possible with a class? Will you get an error at compile time if it is not possible?

View 2 Replies

Web Forms :: How To Use Database Return Many Field And Insert In A Object

Sep 28, 2010

how to use database return many field and insert in a object(like any Collection ,Array,Hashtable etc)

[code]....

View 2 Replies

ADO.NET :: Return A Single Row From A Database As A Strongly Typed Object?

Nov 10, 2010

I have a products table whereby I want to return a single row via a product id and use it as a data object.

I have used a .xsd dataset and a product class where I return a dataset and add the values into the product object that I created but I don't like having to write code like

"Product[0].ProductDescription" to get the product description. Is there a way of returning is straight as an object rather than a dataset?

View 2 Replies

C# - Bypass Non Serializable Properties When Going About Serialization

Nov 12, 2010

I follow the code snippet to calculate Session size. Profile Memory Usage of Session State ASP.Net My problem is some properties of objects aren't marked as Serializable so I cannot apply the solution. Can I just bypass non-serializable properties?

View 1 Replies

C# - Mark A Property As Non Serializable For Json?

Feb 24, 2011

As the title says, I want to mark a property as non serializable by the JavascriptSerializer. How can achive that ?

View 1 Replies

VS 2008 View Page Source - Return Form Object ID's

Mar 10, 2010

How would I go about checking a page for form objects and returning all of the object ID's? I don't even know how to return page source.

View 10 Replies

Architecture :: Method Return Types Object Vs String/bool

May 27, 2010

If I'm returning an object, then it's pretty straight-forward. However, if I'm just trying to return whether or not the method was successful or not, what's the best option? Sure ... bool seems obvious - but what if you need to debug or get some additional details out of the method than just "yes/no"? Well that's where a string becomes more obvious, right? You can leave it empty to say that the method was successful or chock it full of details in the case of an error. But this can make it less intuitive to others who may have to run your functions and it also jumbles up everything you wanted to pass back into one large string.

View 3 Replies

DataSource Controls :: Objectdatasource Return Inserted Object Like LinqDatasource Do?

Mar 5, 2010

I would like the ObjectDatasource insert and update data methods to return the inserted or updated object like LinqDataSource do.

View 2 Replies

Passing JQuery Object And WebMethod Return Value To OnSuccess Function

Mar 31, 2010

I am calling a WebMethod from this code:

if($(this).attr("checked")) {
..
MyWebMethod(variable1, variable2, onSuccessFunction);
}

The MyWebMethod returns an integer, and I want to set $(this).attr("id") of the jQuery object above to the returned integer. Basically, I'm trying to do the equivalent of an MVC Ajax.ActionLink...AjaxOptions {UpdateTargetID =...} However, I can't figure out how to get both a reference to $(this) as well as the returned value. For example, if I do:

MyWebMethod(variable1, variable2, onSuccessFunction($(this)));

I can succesfully manipulate the jQuery object, but obviously it doesn't have the return value from the MyWebMethod. Alternatively, the first code block with a method signature of onSuccessFunction(returnValue) has the correct return value from MyWebMethod, but no concept of the jQuery object I'm looking for. Am I going about this all wrong?

View 1 Replies

AJAX :: Use Return JSON Object From Web Service As A Declared Type?

Jan 3, 2010

I just hit the following issue: I am calling a web service that returns a serialized JSON object let's say: __type, FirstName, LastName (.net object Person with properties FirstName and LastName). __type's value is Test.Person

I have created a JS object using Type.registerNameSpace/registerClass called Demo.Person and it is registered on the page using the ScriptManager. Everything is working fine; I am able to get data from the server on the call back.

Is it possible to make the returned object from the web service be an instance of the declared JavaScript Demo.Person class? The idea would be to call a method like result.getFullName() on the client side without having to copy all the properties. This is just a simple scenario for more complex objects.

View 3 Replies







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