Can Web.config cause "NotFound" error?

Discussion in 'Silverlight' started by FrankParis, May 8, 2010.

  1. My Silverlight application runs perfectly when my WCF Web service is running on my PC. I move it to discountASP.NET and when I try to get to my SQL Server database through my WCF Web service I get an error that Googling informs me could be caused by a thousand different errors, so I'm trying to narrow down what I should be looking at. The error is the following which of course tells you nothing: "The Remote Server returned an error. NotFound"

    Does anybody know whether this error could be caused by anything in the Web.Config file? Mine is pretty simple, here it is, except I removed the connection string for obvious reasons. But the connection string works just fine when the Web service is running on my PC, so that couldn't be the cause of this.

    Code:
    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
    	<system.web>
    		<compilation debug="true"  strict="false" explicit="true"/>
    	</system.web>
    	<system.serviceModel>
    		<behaviors>
    			<serviceBehaviors>
    				<behavior name="">
    					<serviceMetadata httpGetEnabled="true"/>
    					<serviceDebug includeExceptionDetailInFaults="false"/>
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<bindings>
    			<customBinding>
    				<binding name="PHDWebsiteService.customBinding0">
    					<binaryMessageEncoding/>
    					<httpTransport/>
    				</binding>
    			</customBinding>
    		</bindings>
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    		<services>
    			<service name="PHDWebsiteService">
    				<endpoint address="" binding="customBinding" bindingConfiguration="PHDWebsiteService.customBinding0" contract="PHDWebsiteService"/>
    				<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    			</service>
    		</services>
    	</system.serviceModel>
    	<connectionStrings>
    		<add />
    	</connectionStrings>
    </configuration>
     
  2. Hi,
    There are indeed many things that can happen resulting from web.config settings.
    Since it's working locally how about filling us in a bit more, maybe a few more details will shed some light.
    1) Which tool are you using locally...VS or Blend?
    2) Do you know which .NET version you are targeting locally and which you have on the site?
    3) Is your site running on IIS7? If so which mode?
    4) One of the things on-line that can happen with the web.config is inheritance.
    When testing do you have one root web.config and none others?

    Keep in mind I'm just trying to help and I have never messed with WCF. ;-)
    All the best,
    Mark
     
  3. VS2010

    .NET 4.0 locally, and I don't know on the site. How do you configure that? Why wouldn't it pick up what I'm doing automatically on the site?

    No.

    Only one web.config.
     
  4. Actually, let me try to answer this one again. I'm targeting Silverlight 3 for the Silverlight application and I don't know for the Website because I don't know how to configure it. It doesn't have a Project menu like my Silverlight application. But it does have a Website menu. It has a Start Options... command and when I click on it and then choose Build, it says .NET Framework 4, so I guess I guessed right in my first answer to you.
     
  5. Stick the URL to your PHDWebsiteService.svc into your browser address bar and see what you get. If you get an error, run a fiddler trace to see the actual request / response - the real reason for the failure can often be seen in the raw response.
     
  6. ...Fiddler will no doubt help with this:
    http://blogs.msdn.com/fiddler/default.aspx

    You can target SL 3 or 4, as you deploy the client files will be the versioning.
    As for IIS7 and .NET 4, you should consider IIS7 it will give you more options and a better environment.
    In your Control Panel there's an option:
    http://brizzly.com/pic/2DSI

    Keep us posted.
    All the best,
    Mark
     
  7. I installed and ran Fiddler against my Silverlight application, but I don't think I've reached the point where it is going to be useful to me. I'm having much more fundamental problems that have to be straightened out first. There are some very basic deployment steps that I don't know how to make, and running a deployment video I found on DASP.net didn't help, except to totally surprise me by how complex it is to deploy. The video made it look like rocket science, or brain surgery! It went so fast I couldn't even following what he was saying.

    First let me reiterate that I have my Silverlight application and its couple dozen or so Web services working just fine on the PC. Also the database I'm accessing through the PC-resident service is not local: it's a SQL Server database I set up through DiscountASP.

    Anyhow, here are two steps towards deployment that I took that seem to work:

    1. I copied the .xap file to the ClientBin folder on my Website
    2. I copied my TestPage.aspx file to the root of my Website and renamed it Default.aspx

    What I'm supposed to do next totally mystifies me. There's these lines in the Reference.svcmap file autogenerated by VS1010:
    Code:
    <MetadataSources>
        <MetadataSource Address="http://localhost:64341/PHDWebsite.Web/PHDWebsiteService.svc" Protocol="http" SourceId="1" />
    </MetadataSources>
    This obviously won't work since the Address must be on the Website. But the .svc file gets compiled into my .xap file, doesn't it? Somehow I have to specify an Address that looks something like this:
    Code:
    http://www.parisphototools.com/something_or_other/what???
    where www.parisphototools.com is the name of my DASP.NET Website.

    There's also another file called Services.References.ClientConfig that also has the endpoint address that needs to be changed, but changed to what I don't know. The only thing I know for sure is that the address has to start out with the following:
    Code:
    http://www.parisphototools.com/???
    where ??? is what I don't know, except that somehow it has to end in a .svc file that I don't know where to put on the Website, mainly because I'm under the impression that it has to be compiled into my .xap file.

    I might add that the first two steps in the numbered list above do get my Website displayed and all of the functionality is there that doesn't have to access the database. You can test it out for yourself by clicking on the above link.

    What does not work on this Website is the Login and Register buttons, because they both need to access the database and I don't know how to hook up to it from the Website, only from my PC.

    Not that it's very enlightening, but the error message I get back from my service when I click the Login button is the infamous,

    "The remote server returned an error: NotFound."

    You can see for yourself by trying to log in (just use something made up, we only actually get to the database if the Silverlight application is executed from VS2010).
     
  8. ...Wow ;-)

    Hopefully someone here can help with your .svc questions.

    As for the ClientBin and.xap file you can move those around and duplicate them.
    If you don't think it's getting found copy the folder and file to other sub-folders as needed.
    You probably already know the .xap file is a ZIP compression archive that contains at minimum a binary library and manifest file.
    All the best,
    Mark
     
  9. The URL before or after I deploy to the Website? I don't know what it's supposed to be after I've deployed, which of course means that my attempt to deploy is incomplete and so of course the deployment doesn't work.

    When I followed your advice using the URL before I've deployed, I got a Web page entitled "PHDWebsiteService Service" claiming that I've created a service, with instructions to test the service. I presume that this is not an error, which I guess is not surprising, since the Silverlight application runs just fine from the PC.

    So I need advice on how to deploy, since that's where I am in my development cycle. My Silverlight application and my WCP services run perfectly on the PC.
     
  10. Those are the only questions I have.

    But I know that the .xap file is being found: the Website runs! Click on this link http://www.parisphototools.com to see for yourself, as I suggested you do in the post you're replying to.

    Yes, I've looked into it and it has lots of stuff in it, not just the minimum. I guess I'm using a lot of Silverlight functionality.
     
  11. There seems to be some confusion - here's the thing(s). Your svc file is a markup file for your wcf service that needs to be hosted server side on the web server; it doesn't get packaged into the xap. I think you know that the xap is a zip file package that contains silverlight xaml and client side assembly code that gets downloaded and executed by the Silverlight runtime plug in, in the end users' browser.

    At the moment the reason your application is chucking a not found exception is because the wcf service does not exist on the server at the location the silverlight application is requesting it from. The silverlight application appears to think that the service is at the root of your account web space - in other words it's making a request for http://www.parisphototools.com/PHDWebsiteService.svc and the web server is returning a 404 because this requested resource just doesn't exist. It's an easy one to see - when I put http://www.parisphototools.com/PHDWebsiteService.svc into my browser address bar and hit return I see the 404 error.

    So right now if your wcf service is actually hosted, it's not where the silverlight application thinks it should be and if it's not hosted..obviously it needs to be. There are other reasons for getting a 'not found' in a Silverlight application with a WCF service, but yours is cut and dry.

    You're right that it shouldn't be too difficult to deploy a web application to the server but to be fair it's not a problem specific to DASP web servers; in fact I have exactly the same types of problem in my day job with internal web servers at the company I work for. The most complete way to deploy a web application is to have complete understanding of where everything needs to be and then when problems do occur at deployment time, they're fixed pretty quickly.

    My suggestion to run the fiddler trace was intended to be executed after deployment to find the cause of the problems i.e. now. Everything I've described in this post has been done after running a trace on your site and attempting a login.

    If I've stated stuff you already know please forgive me; just trying to help.
     
  12. Okay. This is actually the first post I've received from two different threads on this site that actually has some substance to it.

    Yes, you are obviously trying to help and I really appreciate it! We just have to hone in on what I need to do. The first big insight you gave me is this:

    That is monumental news to me and is going to be a big help to me in understanding what I have to do.

    One of the things that has puzzled me is whether the xap file also contains the host-side server code. I've been thinking that it somehow gets packaged up in my main assembly. If not, where does it reside? I've been looking for a different assembly that might contain the server code but I haven't found anything else but the main Silverlight assembly.

    Yes, I understand that that is the crux of the problem. But what contains it? Where is it when I'm running from my PC? What piece is it in?

    That was just a placeholder because I didn't know what else to make it. I did put the .svc file in that location, but I knew it wouldn't work and of course it didn't. I also tried to put it in the same locations as my xap file, but of course that didn't work, either.

    So that's the monumental question: how does it get hosted?

    If only my question has a cut and dry answer! I will be eternally grateful to the person who explains to me what I have to do to move forward on this.

    I hope you're not saying I'm not on the right forum! I realize I'm searching for the answer to generic questions, but at least I'm paying money to DASP and so I'm hoping they'll cut me a little slack and stick with me until my problem is resolved. I'd be a great reference for their tech support if I get my answers up here!

    However, I knew it wouldn't tell me what I need to know because I'm at a loss about what I need to do to locate my Web service anywhere! How do I get it as an isolated component so I can address it? And what do I have to put in the .svc file to point to it?

    At least I hope I'm asking some questions that will expose other things I'm confused about and you have a better understanding of what I don't understand.
     
  13. Substance - good. I think everyone on here does their best to help where possible, but it can be difficult because sometimes there's not much information to go on.

    When you create a SL application in VS2010, the project template asks some questions about how the SL application will be hosted. One of the options is "Host the SL application in a new website?" checkbox. When you do this. the result is a new VS solution that contains 2 projects:
    • MySLProject
    • MySLProject.Web
    The one that ends up with the .Web on the end is intended to contain the server side ASP.NET code and the other one is intended to contain the Silverlight XAML and client side code.

    It is possible to extend this structure to contain further web and SL assemblies and link them together by project references but for now we'll just concentrate on the simple example above as a way to explain the theory.

    So the next thing to think about is how your code is structured. This matters because it should clearly show the separation between client side and server side code and you should be able to see from this where your WCF service(s) fits into the bigger picture.

    As I mentioned in my previous post, the .svc file and WCF service code does need to be hosted server side so in the simple solution example above, the WCF service could actually be hosted in the MySLProject.Web project. It doesn't have to be (it might actually be in it's own project), but it could possibly reside in the MySLProject.Web project.

    If you locate the svc file in your project structure, right click on it and go "View Markup". In there you'll see a code behind directive for the service that tells ASP.NET where the code for the WCF service resides. Hopefully from this you can see that it's not enough to simply upload the PHDWebsiteService.svc markup file to the root because it is actually dependent on some code (the ServiceContract, DataContracts etc) to make it all work.

    There's more to go yet on the ServiceReferences.ClientConfig file and what that contains and also how Silverlight applications can better determine the location of the WCF services they depend on at runtime, but I'll let you digest this lot before posting any more.
     
  14. I did check the option, "Host the SL application in a new Website" so I do have both a PHDWebsite project and a PHDWebsite.Web project, and I do host all my Web service code in the .Web project. My .svc file has the following line:

    Code:
    <%@ ServiceHost Language="C#" Debug="true" Service="PHDWebsiteService" CodeBehind="~/App_Code/PHDWebsiteService.cs" %>
    Everything that you describe is what I did and intended: I have a clear separation of client-side and server-side code. The problems I'm having are all concerned with deployment from my local PC to the DASP Website, and how to do that. You say,

    and indeed it is.

    In referring to the contents of the .svc file, you say,

    So my question remains, how do I get the code containing the ServiceContracts onto the DASP Website? I have looked for it diligently under the .Web folder on my development machine and there just isn't anything there big enough to contain it. The only large file in there is a copy of the xap file in the ClientBin folder.

    I just had a thought (insane though it seems to me). Could it be that the Website expects to see the service in source code format??? Could it actually be compiling it on the fly??? I think I read something somewhere that actually implied this, but it seemed so absurd to me that I just dismissed it as something I was simply not understanding. All of this Web service source code in App_Code amounts to almost 100,000 bytes of C# that would have to be compiled, which seems like quite a lot to be compiling every time someone opens the site.

    There's even more in the App_Code folder in the .Web project besides the source file for the ServiceContracts. I'm accessing the SQL Service database with ADO.NET and all of that ADO.NET code is in a separate .cs file with functions that the actual ServiceContracts call. There's even a third .cs file that contains a single function that converts a password to a hashed password for storing in the database.

    So in wondering how the Website gets all this source code in compiled form I've narrowed down some of the misunderstandings I have about how all this is supposed to fit together.

    In your last paragraph, you wrote:

    Yes, that's another piece of the puzzle I have to wrap my head around. That file is in the root of my client-side project and has a statement of the service endpoint (address, binding, and contract).

    So I think I'm ready for another installment from you!
     
  15. Hi again,
    I won't move onto the ServiceReferences.ClientConfig stuff yet because I think we're getting close to getting your service deployed. This says a lot about what you've done:
    This shows the code for your WCF service is in the app_code folder which means that you're using an ASP.NET web site rather than an ASP.NET web application; yes two different ways to acheive the same thing with ASP.NET!
    I won't go into the details why these two methods exist side by side (you can look that up for yourself) but in your case, you won't have any assemblies in the bin folder for your web application and the code for your WCF service and other web classes will get compiled to executable code as required. In reality the code is not compiled on every visit but only one time on spin up of the web application domain (so it's not too insane) and if you want to, you can precompile to improve performance.

    So you need to be sure you have uploaded all the app_code folder to the server and also the svc markup file. If you do that and you still have a problem, feel free to post again.
     
  16. Okay, so I know where to put the .svc file: in the root of the Website. But I'm not sure where to post the service code files. I'm guessing for my case, here:

    Code:
    http://parisphototools/App_Code
    Is that correct? The Website just assumes that any .cs files it finds in the same location as my service .cs file it also compiles? I'll try that and let you know.

    Then I have to figure out how to have one configuration for my endpoint definition for debug builds and another for release builds, so that I can continue debugging locally. I know I ran across how to do this somewhere. I certainly don't want to hard-code this endpoint for both debug and release. But in the meantime I'll hard-code it and see what happens.
     
  17. Website won't compile service

    Now the Website won't compile the service, but apparently at least it's trying because it picked up one of the files in my App_Code folder on the Website. Below is the screenshot of the compilation error. It looks as if DASP thinks I'm using .NET 2.0. How is this possible? DASP claims it went to .NET 4.0 weeks ago.

    http://parisphototools.com/WebSite/ServerError.png
     
  18. Yes ~/App_Code/PHDWebsiteService.cs in your .svc markup file is specifying that the App_Code folder is expected to be at the root (~ specifies the root of the current web application in ASP.NET).

    Once the .svc file is present at the root you might want to try the suggestion in post #11 e.g. put the URL http://www.parisphototools.com/PHDWebsiteService.svc into the browser address bar and hit return. Hopefully you'll see a service test page when you do this; if not you probably still have some sort of issue.
     
  19. Can't expose my source code this way!

    I just realized that I can't expose my source code this way! There's proprietary algorithms in it, for example, my license key generator! You mentioned something about precompiled source. How do I do that? That will do until I figure out how to obfuscate the compiled code. So I need two pieces of information:

    1. How do I make the Website use the .NET 4 libraries?
    2. How do I precompile my service code so I don't have to post source to the Website?
     
  20. That's a good way to see my compilation error.
     
  21. Strange one. Do you have a reference to System.Core in your web site? Do you have entries like these in your web.config?:

    • <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    • <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
     
  22. What do you mean, "in your web site"? All my .cs files in the .Web project obviously compile on my PC, although they don't have this particular Directive:

    Code:
    using System.Core
    They apparently don't need it for correct compilation.

    Absolutely not. I didn't know about them and my reference book doesn't mention them. Besides, I don't want .NET 3.5, I want .NET 4.0. Is there some way to automatically generate those entries in my web.config file? If not, how do I find the information so I can manually enter them?

    Boy, there sure is a lot to all this stuff. Desktop application programming is 100 times easier than Web programming. It's so hard I'm amazed there are so many people doing it. Maybe I think desktop programming is easier because I've been doing it for almost 20 years. Sorry for the editorializing. I think we're getting closer, but who knows how many "gotchas" lie ahead?
     
  23. Does Web.config file need to be on Website?

    I just noticed that the Web.config file is in the .Web project, but I didn't copy it to the Website. This is what I have in my Web.config file:

    Code:
    <system.web>
    	<compilation debug="true" targetFramework="4.0"/>
    </system.web>
    I'll put my Web.config file on the Website and see what happens. I guess it has to be in the root, along with the .svc file.

    Edit:
    I tried several things and none of them are working. First it complained that targetFramework wasn't recognized so I took it out and put in those statements you supplied me with the public key tokens. You didn't give me enough of them, so I made some up to see if I could get rid of the compilation errors. Nix. Where do you pick up those public key tokens? They look like magic numbers.
     
  24. My fault. Those references are required when targetting .NET3.5; you're targetting .NET 4.0 so you don't need them in your web.config.

    It looks like there's something fundamentally wrong with your web.config at the moment. You application is throwing exceptions that indicate your web.config is set up to partially target .NET3.5 but you mentioned you intend to target .NET4.0. I don't know why that is or how it's ended up like that.

    In VS2010 right click on the PHDWebsite.Web project in the solution explorer and click Property Pages. Then go to the Build options. Do you see Target Framework .NET 4.0?
     
  25. Yes. I restored my Web.config file back to its original state. I can now once again compile correctly on my PC. But the Website still thinks I want .NET 2.0 and objects to my targetFramework attribute. There must be something else that tells the Website to use .NET 4.0. I'm thinking the targetFramework attribute is something new with 4.0 and if the Website doesn't realize it must run with 4.0 it won't get very far parsing my Web.config file.

    I'm reading about the Web.config file from this article:

    http://support.microsoft.com/default.aspx/kb/815179?p=1

    It pointed me to machine.config and that contains all the public key tokens I was asking about for .NET 4.0. Since they're all in machine.config and Web.config inherits from machine.config, I don't need any of them. But we're still back to the question of why DASP insists on compiling under .NET 2.0. So the question is, how can we tell DASP to run under .NET 4.0?

    Note this from the above link:

    The problem is, if the Website's Machine.config file specifies .NET 2.0, it doesn't matter if I override the .NET version with my own Web.config file, since the Website will be running under .NET 2.0 and won't recognize the targetFramework attribute. Since DASP proclaims so loudly that it is now running under .NET 4.0, it's hard to believe that this is the problem.
     
  26. In IIS tools in the DASP control panel there is the ASP.NET framework version selector..do you have that set to .NET4.0?
     
  27. That was it! I thought there had to be something like this, but I don't know enough about Web architecture to know where to look. I guess I just should have started clicking on every button!

    Now I have to spend a few minutes restoring my Silverlight solution to address the Website rather than the localhost.

    In the meantime, I'm finding huge security holes in what we're trying to do. I forgot that I was putting my connection string in my Web.config file for all the world to see, since this architecture requires me to put the Web.config file in the root of my Website. It seems insane that the recommended practice is to put your connection strings in Web.config. Right out there in public view!

    Anyhow, in the next few minutes I'll discover what the next land mind I step on is.

    Edit: And the land mind is:

    Examining my solution, I found 18 references to localhost. It would boggle my mind if I had to go through all this and make manual changes. I thought all I'd have to do is change it in one place, in the ServiceReferences.ClientConfig file, then compile my Silverlight project. But that's not how you do it. Do you what I was supposed to do?
     
  28. Result. So in the end there were 3 issues with your WCF service and web app as a whole:
    1. The WCF .svc file was not uploaded
    2. The App_Code folder and the .cs files it contains were not uploaded
    3. The wrong ASP.NET framework version was selected in the DASP control panel
    This now works in the browser address bar as it should:
    http://www.parisphototools.com/PHDWebsiteService.svc

    The problem you now have with your Silverlight application consuming the WCF service is related to missing clientaccesspolicy.xml / crossdomain.xml files:
    http://parisphototools.com/clientaccesspolicy.xml - 404 error
    http://parisphototools.com/crossdomain.xml - 404 error
    Again - run a fiddler trace to understand what I'm on about and when you can see the problem refer to this to fix it:
    http://www.silverlight.net/learn/vi...e-cross-domain-policy-files-with-silverlight/
    Here's the verbose MSDN version: http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx
     
  29. Yes, we've resolved the three issues you identified. Very grateful for your help.

    I'm not sure that your comments about the clientaccesspolicy.xml addresses the problem of switching between localhost and the DASP Website in my code. While I was waiting for your reply, I think I've made it easier to make this switch. I got this idea from Matthew MacDonald's book, Pro Silverlight 3 in C#, pp. 524-526 (in case you have the book; in general I really like this book, but it is weak on deployment (but better than any other book out there), concentrating almost exclusively on using localhost). Basically, I create a System.ServiceModel.EndpointAddress object, depending on whether I'm in a debug or a release build and set it to my proxy (unfortunately in about 15 different places, but it's not horribly painful).

    As for your suggestion about the clientaccesspolicy.xml file, I was wondering if this would arise as an issue. I thought it might be relevant a couple days ago and built one and tried it out. Of course it didn't work because of the other issues which we solved today. So I'll go back and try it again, looking into the references you supplied to see if they tell me anything different from what I learned a couple days ago.

    But one thing you could perhaps clear up for me. I'm wondering why this is a cross-domain issue. My wonder stems from my lack of precise knowledge about what exactly a "domain" is. I know about different domains on the Web, but is my PC itself considered a domain different from (say) my parisphototools domain, irrespective of localhost issues, which I believe I've solved with the code behind that sets the EndpointAddress.

    Meanwhile, I have to take a food and exercise break. I hope you can at least clear up the issue about cross-domains before I get back to work on this. See you later, then.
     

Share This Page