Friday, July 13, 2007

How do I upload & download files using WCF?

I'm looking for the best way to accomplish these tasks. What follows is the best information that I've found. I will periodically update this post as I discover more information.

Examples:

WCF gotchas:
  • Don't forget to set the maxReceivedMessageSize attribute of your binding to something fairly high if you are sending large files.

IIS gotchas:
  • Increase the maxRequestLength, which represents maximum length in kilobytes, in the System.Web section of my web.config file in order to upload large files to your server (i.e., < maxrequestlength="65536"> ). Remember that the reason maxRequestLength in the System.Web section was set so low was to decrease your vulnerability to denial-of-service attacks.


Articles worth reading:

Thursday, July 12, 2007

How to generate an XSD file from an existing class

Since one of my co-workers ask me how to generate an XSD file from an existing class today, I decided to post an example of how to do it.

First, I need a class to convert, so I will generate an XSD file from this class, which resides inside of an assembly called MyClassLibrary.dll:

using System.Xml.Serialization;

namespace MyNameSpace
{
[XmlRoot("Customer", Namespace ="http://www.yates.com/BusinessObjects/2007/07")]
public class Customer
{
private string _firstName;
private string _middleName;
private string _lastName;

public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}

public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}

public string MiddleName
{
get { return _middleName; }
set { _middleName = value; }
}

[XmlIgnore]
public string Name
{
get
{
if (string.IsNullOrEmpty(MiddleName) == false)
return string.Format("{0} {1} {2}", FirstName, MiddleName, LastName);
else return string.Format("{0} {1}", FirstName, LastName);
}
}
}
}
Next, a command prompt window is opened in the same directory as MyClassLibrary.dll.

Afterwards, the following command is used to generate the XSD:
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\xsd.exe" MyClassLibrary.dll /t:Customer



Finally, an XSD file called schema0.xsd is generated in the same directory as the assembly. It looks like this:

Monday, July 2, 2007

Unable to add a WCF service template to a converted project

I filed a bug at Microsoft's feedback web site on Friday because I was unable to add a WCF service template to a converted project in Visual Orcas March 2007 CTP.

It turns out that it wasn't really a bug. I was ignorant of the fact that you need to change the target framework from whatever it was originally set to (in my case ".NET Framework 2.0") to ".NET Framework 3.0" or ".NET Framework 3.5".