locked
How to deploy OData Service to IIS 5.1 using VS2010 RRS feed

  • Question

  • I've been searching all over the web and I couldn't a clear answer on publishing OData service to the server.  The resources I did find didn't prove to helpful to me.  I'm really new to this, so I would greatly appreciate your help.

    I have a Win XP Pro with IIS 5.1 installed.  The PC has upto version 4 of .Net Framework.  I also have VS 2010 Ultimate installed on the same PC.  I am using the NorthWind DB which is on a different PC.  I'm using an OData service to connect to the NorthWind DB.  I'm able to view the service through Visual Studio's localhost.  However, I think I might have published or deployed OData service wrong to IIS.  I would like to view the OData service from other PC's within my network and consume it.  

    After I publish the OData Service, I get the message: 

    <error> <%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0...</error>

    This is my code:

     

    using System;
    using System.Collections.Generic;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Linq;
    using System.ServiceModel.Web;
    using System.Web;
    
    namespace myODataService
    {
     public class NorthWindService : DataService<NorthwindEntities>
     {
     public static void InitializeService(DataServiceConfiguration config)
     {
      config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
      config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
     }
     }
    }
    

     

    Would you provide detailed step-by-step instructions?  Or point me in the right direction?  I would really like to have OData, but if it's wrong for me, please provide alternate suggestions.

    Thanks in advance.


    Wednesday, April 20, 2011 1:04 AM

All replies

  • Hi,

    Could you please post the full error message?

    Thanks,


    Vitek Karas [MSFT]
    Wednesday, April 20, 2011 4:13 PM
    Moderator
  • @Vitek:  Thanks so much for responding.

    The full error is:

    <error>

    The XML page cannot be displayed

    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


    A name was started with an invalid character. Error processing resource 'http://localhost/ODataService/NorthWindService.svc'. ...

    <%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Service="myUserService.NorthWindService" 	%>
    -^

    </error>

    If you need more info, please let me know.

    Thursday, April 21, 2011 1:12 AM
  • I'm not very familiar with IIS 5.1, but it looks like it doesn't have a registered handler for the .svc extension, and is just trying to render the file as xml.

    In a sense, a WCF data service looks like any other .svc to IIS, so its possible these links might help (found from a very quick search, by no means definitive):

    http://forums.asp.net/t/1024882.aspx/1/10?A+name+was+started+with+an+invalid+character

    http://social.msdn.microsoft.com/forums/en-US/wcf/thread/6e463ae3-6143-4b68-b5f3-3cfa80fecc7e/

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/3d8aa2ae-1fd3-4cb6-b8fb-5544b2eaab24/

    Hope that helps!

     


    Matt Meehan (WCF Data Services / OData)
    Thursday, April 21, 2011 1:49 AM
    Moderator
  • Thanks @Matt.

    I've tried the suggestions mentioned and I came up with this error:

    <error>

    Line 10:   </connectionStrings>
    Line 11:   <system.web>
    Line 12:     <compilation targetFramework="4.0">
    Line 13:       <assemblies>
    Line 14:         <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    </error>

    I've checked Web.Config and it has:

    <code>

    <connectionStrings>
        <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
        <add name="NorthwindEntities" connectionString="metadata=res://*/NorthWindModel.csdl|res://*/NorthWindModel.ssdl|res://*/NorthWindModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=OCDT70276566;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>

    </code>

    Quick question, can I use OData or WCF Data services on IIS 5.1?  Would OData & Ado.Net be compatible with a .Net Framework less than 4?


    Thursday, April 21, 2011 7:59 PM
  • WCF data services first shipped as ADO.NET Data Services in 3.5 sp1 along with the first version of the Entity Framework, so yes, they work on a version of the .NET framework less than 4.0 (but only 3.5sp1). Note that there was also an updated hotfix release for data-services on 3.5sp1 to bring in all the features added in 4.0.

    I don't quite understand what error you're getting, since i don't see any actual error message, just a subset of the web.config you provided.

    I will try to find someone with more expertise on IIS and reply again shortly.


    Matt Meehan (WCF Data Services / OData)
    Thursday, April 21, 2011 8:26 PM
    Moderator
  • Thanks @Matt.  Hope you had a great Easter.

    In the meantime, I've got a hold of Win 7 box.  I'm going to try my luck on IIS 7 and see if I get anywhere.  However, our server environment is Win Server 2003 with IIS 6.

    @Matt, as mentioned earlier, I found OData to be so much easier to a novice.  I'd like to stick with that functionality.  However, if there are other alternatives, I will pursue them.  Let me know.

    Monday, April 25, 2011 4:18 PM
  • Hi again,

    Unfortunately, I haven't been able to figure out what the issue is based on what you've provided.

    Can you install a web debugger like Fiddler (http://fiddlertool.com) and post the entire response payload you are recieving? It looks like part of the error is not included in your earlier post. Using something like Fiddler will ensure that you are seeing the full payload and not just a part of it (which could happen in IE or another browser).

    Thanks.


    Matt Meehan (WCF Data Services / OData)
    Friday, May 27, 2011 5:41 PM
    Moderator
  • Hi Guys

    I seem to be having a similar issue. I am using Windows 7 also Visual Studio 2010 and am really enjoying OData as a technology. Although the backend language i'm using is visual basic. I was asked to research OData and have managed to learn and understand the concept quite easily. The only issue is when I deploy my project into a live environment (or even just to view within our company's network) It does not display the data at all and I get an XML error. "An error occurred while processing this request."  As you can see, pretty much the same issue as inquisitive_one. Also absolutely no issues when I run the solution locally. 

    Last week sometime I had to register the .svc MIME into IIS 7... So that .NETframework v4 can recognize service pages. That in itself was a mission. Yes all good and well it now recognizes services. But still I am unable to see the data I want, externally.

    The only massive difference in my code behind, to inquisitive_one's is that I added :

     config.UseVerboseErrors = True

    to the InitializeService()  method(or sub in my case)

    This showed me the same XML error as above but with a bit more detail :

     

    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
     
    <code/>
     
    <message xml:lang="en-US">An error occurred while processing this request.</message>
     
     <innererror>
     
    <message>The underlying provider failed on Open.</message>
     
    <type>System.Data.EntityException</type>
     
    <stacktrace>
    at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Data.Objects.ObjectQuery`1.GetEnumeratorInternal() at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable) at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService) at System.Data.Services.DataService`1.HandleRequest()
    </stacktrace>
    <internalexception>
    <message>
    Cannot open database "Northwind" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.
    </message>
    <type>System.Data.SqlClient.SqlException</type>
    <stacktrace>
    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
    </stacktrace>
    </internalexception>
    </innererror>
    </error>

     

    I went to a bunch of forums all stating an issue with my SQL Server authentication setup, (Mostly referring to Mixed Mode Security). So I made the necessary changes, still to no avail and still receiving the error as above... I am not sure it is an issue with SQL and I'm not sure if it is an issue with my .Net Framework setup or if it is to do with the WCF Data service itself... I have tried consuming data using OData from the Producers displayed at OData.org (Nerd Dinner to be more specific), the query is simple, there are no javascript errors and still, the data will not display as it should. Here is my code for both the Service and the .ASP pages of my own demo project:

    VB Code :

    Imports System.Data.Services
    
    Imports System.Data.Services.Common
    
    Imports System.Linq
    
    Imports System.ServiceModel.Web
    
    
    
    Public Class NorthwindService
    
    
    
      Inherits DataService(Of NorthwindModel.NorthwindEntities)
    
    
    
      ' This method is called only once to initialize service-wide policies.
    
      Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
    
    
    
        config.UseVerboseErrors = True
    
    
    
        config.SetEntitySetAccessRule("Products", EntitySetRights.AllRead)
    
        config.SetEntitySetAccessRule("Categories", EntitySetRights.AllRead)
    
    
    
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2
    
      End Sub
    
    
    
    End Class
    

    Asp.NET Code :
    <body style="background-color: Black;">
    
      <form id="form1" runat="server">
    
        <table width="750px;" style="margin: Auto; background-color: White;">
    
          <tr>
    
            <td style="padding-left: 15px; padding-right: 15px;">
    
              <img src="OData_logo.jpg" alt="" />
    
              <p>
    
                <b><u>Reading data from the Northwind DB using OData</u></b></p>
    
              <b><a href="#" id="loadData">Load Data</a></b>
              <div id="status">
              </div>
              <br />
              <div id="products" style="padding-left: 5px; padding-right: 10px;">
              </div>
              <br />
              <a href="ReadMore.aspx">Click here to read more.</a>
            </td>
          </tr>
        </table>
      <script type="text/javascript">
    
        $(document).ready(function () {
    
          var qry = "http://john-pc/PracticeOData/NorthwindService.svc/Products?$filter=Discontinued%20eq%20false&$orderby=ProductName";
    
          $('#loadData').click(function () {
    
            $('#status').text("As you can see the XML data is simplified... Now Try click on each row to view a little more data :) ");
    
            $.getJSON(qry, function (results) {
    
              $.each(results.d, function (i, item) {
                var line = "<div id='rowDiv' class='infoDiv'>" + item.ProductName + " : | <i class='tags'> Units in stock </i> : " + 	item.UnitsInStock + " | <i class='tags'> Quantity Per Unit </i> - " + item.QuantityPerUnit + "<br />
    					<div	class='extraInfo'>"
    					+ " Product price : $ " + item.UnitPrice + "</div></div>";
                $('#products').append(line);
              });
            });
          });
          //      $('#loadData').trigger('click');
          $('.infoDiv').live('click', function () {
            $(this).find('.extraInfo').toggle();
          });
        });
        
      </script>
    </body>
    


    Is it something that I am doing wrong in my code? I do not understand how it is that I can run everything locally and it works out perfectly.

    But as soon as I attempt to view the data from anywhere else besides my local machine, it refuses to display anything, as well as when I try to consume data from any outside resources... If I run the query from an outside source in my browser, it shows the data perfectly as it should in XML format (Atom Pubs) but if i implement that specific link query into a project of my own (via Jquery), it will not display the data I requested.

     

    Thank you in advance, perhaps my post will spark an idea that might help both, inquisitive_one and myself.

     


     

     

     

     

    Monday, June 13, 2011 1:43 PM
  • Hi,

    You're not doing something wrong in the code, and there is nothing wrong with the data-services part of it either.

    What you're seeing is an authentication issue between SQL and IIS/ASP.NET. Basically, the server-side code runs as some user ('IIS APPPOOL\ASP.NET v4.0'. in your case) and that user may or may not have permission to talk to the database.

    The most common approach here is to use some authentication scheme to identify the current user, then use their credentials when talking to the database. Alternatively, you could change the identity that the application pool runs in so that it will be able to access the database. Try looking up ASP.NET impersonation/delegation for more info, I'll try to find some links and reply back later. I am by no means an expert on this stuff, and because its a security concern you really should read up on different options.

    Overall, this is all configuration-level stuff that is mostly the same for any ASP.NET site hosted in IIS, and has nothing to do with the data-service code itself or the client code. You might have to change how your service initializes your ObjectContext, but otherwise there's no part of the data-service that is even aware there is a database. Once you have authentication set up, its relatively straightforward to change the client code to use the right authentication, though I'm not familiar enough with JavaScript to know how.

    UPDATE:

    Alex James has created a series on how to do authentication with OData that you should check out. You might want to start with these first two:

    http://blogs.msdn.com/b/astoriateam/archive/2010/05/10/odata-and-authentication-part-1.aspx

    http://blogs.msdn.com/b/astoriateam/archive/2010/05/10/odata-and-authentication-part-2-windows-authentication.aspx


    Matt Meehan (WCF Data Services / OData)
    Monday, June 13, 2011 4:48 PM
    Moderator
  • Hi Matt.

     

    Thank you for your reply. I understand your response completely. I am somewhat new to WCF so this is a massive help.

    I am following the links you've sent which are quite helpful. I will let you know as soon as I have solved the problem and I will post the full solution in the reply.

    Thanks again for your help I appreciate it.

    Tuesday, June 14, 2011 11:22 AM
  • Matt,  I've changed my WEB.CONFIG to use FORMS authentication.  I have a device that uses HTTPS to send login/password.  I also have a DB that houses users login/password info on an SQL server. 

    Based on my webservice above, I assume that I can use a QueryInterceptor to validate the HTTPS login/password against the DB.  But how would you set it up?

    Wednesday, August 17, 2011 7:10 PM