Question: Im developing a WCF web service with receives always and only XML.

So i need to validate that input XML using their XSD. The question is, can i save them inside web service? Locally i can access XSD files via relative path into IIS Express root folder which i created manually. I tried add the XSD files in VS project but i just cant a find them on runtime.

I'm using the Shemas like this: [Image1 Link](http://s16.postimg.org/cmnm850lh/image.png)

IIS XSD'd Folder Path Workaround: [Image2 Link](http://i.stack.imgur.com/ePozA.png)

At the moment, its working fine, the problem will be when i try deploy the service somewhere on internet.  

Thank you.

**tl;dr: Can i send some XSD when deploying the webservice or its just impossible?**

Answer: 
Files that belong to your solution should be **physically** part of it. Once that is the case you can use for instance [`HostingEnvironment.MapPath`](http://msdn.microsoft.com/en-us/library/system.web.hosting.hostingenvironment.mappath%28v=vs.110%29.aspx); or look at the answers to [this question](https://stackoverflow.com/questions/791468/how-to-get-working-path-of-a-wcf-application). Note that there is [a possible issue](http://blogs.msmvps.com/theproblemsolver/2009/02/08/gotcha-with-hostingenvironment-mappath/) with HostingEnvironment.MapPath when the WCF service is self hosted.

A possible solution is this method:

```
public static string MapPath(string path)
{
    if (HttpContext.Current != null)
        return HttpContext.Current.Server.MapPath(path);

    return HostingEnvironment.MapPath(path);
}

```

The parameter `path` needs to be of the format `"~/XSD/MyFile.xsd"`, with the folder "XSD" being located in the root of your WCF service.

NEVER create folders in `c:\program files (x86)\iis express`.
You can add the XSD as a resource, then load it from your assembly. Add the XSD to your project, and under the "Properties Explorer", set the "Build Action" to "Embedded Resource". You can then read the file with:

```
var schemaSet = new XmlSchemaSet();
schemaSet.Add("", XmlReader.Create(typeof(SomeClassInTheSameAssembly).Assembly
    .GetManifestResourceStream("Full.Namespace.XsdName.xsd")));

```

See [Working with Embedded Resources](http://blah.winsmarts.com/2006-12-Working_with_Embedded_Resources.aspx) or [Loading XmlSchema files out of Assembly Resources](http://www.hanselman.com/blog/LoadingXmlSchemaFilesOutOfAssemblyResources.aspx) for more.