Silverlight Web.Config Setting for Web Service Reference URL? - asp.net

I have a Silverlight control that is hosted within an ASP.NET application. The Silverlight control has a web service reference. The URL of this service is going to vary when we install the application for our customers. I need a way to be able to change this web service reference URL from within the web.config of the ASP.NET application. How can I do this?

You could do something like http://dev/foo/bar.svc where dev is an entry in your hosts file which will resolve to where the service resides.

If you are using Silverlight 4 you can use urls relative to the page the silverlight app is hosted on. So in ServiceReferences.ClientConfig you can change your endpoint addresses to be relative, say from http://localhost/foo/bar.svc to /foo/bar.svc.

Related

Routing fails when api is created as a web application under another site

I developed a rest api using ASP.net web api. When I deploy this rest api on iis, I need to create it as a web application under an asp.net web site. When I was deploying the rest api as a new web site in iis, then things worked fine. I was using the following Route api/{controller}/{id}.
When I created the rest api as a web application underneath asp.net web site project, I named the web application as api. I can't access the api methods now. Can someone point what I do wrong?
WebApi is based on global.asax and web.config configurations and you can't have 2 of these files inside in the same application. In the scenario you described, it sounds like you need to create a "Virtual Directory" in IIS for the second application instead of making just a "Sub Folder".
The Virtual Directory will allow you to declare a new web.config and global.asax where you set the new routings and configurations method for your second application.
For a full walkthrough on how you can perform this please refer to this site:
http://msdn.microsoft.com/en-us/library/vstudio/bb763173(v=vs.100).aspx

ScriptManager service reference generates JS code that forgets about the service host name

I'm working on an ASP.NET project that uses AJAX to communicate with an ASMX web service. One of the pages uses a ScriptManager to reference the web service ASMX file. It's referenced using an absolute URI.
I recently changed both the ASP.NET project and web service to use IIS Express. Each now has a different port number. Since this change, the client-side code for the ASP.NET project can't access the web service.
The generated HTML code for the ASP.NET page contains a correct reference to the web service:
<script src="http://localhost:2837/Service.asmx/jsdebug" type="text/javascript"></script>
However, this script only refers back to the web service using a relative URL instead of an absolute one:
Service.set_path("/Service.asmx");
So AJAX calls to web service methods fail because the hostname from the ASP.NET application is used instead of the web service's:
POST http://localhost:2827/Service.asmx/WebServiceMethod 500 (Internal Server Error)
Notice that the port number above is different to the one used by the web service. The above port number is the one used by the web application.
The HTTP 500 is produced because the web server is reporting:
No web service found at: /Service.asmx
How can I fix this so that the web service is referenced correctly?
From Exposing Web Services to Client Script:
The ServiceReference object can reference a Web service only in the
same domain as the page. The Web service path can be relative,
application relative, domain relative, or absolute. For absolute
paths, you must make sure that the path is in the same domain.
So you can't call your web service method which is in another domain. What you can do is create another service in your asp.net project to call the original web service. then you can call newly created web service method from script manager

Separate httpmodule(s) in web.config for a WCF web service within an ASP.NET website

I've got a WCF (RESTful) web service within an ASP.NET website project. The service resides at /WebServices/Registration.svc. I'm trying to create a custom BasicAuthenticationModule httpModule to handle Basic Auth as explained at https://stackoverflow.com/a/4729555/291323, but the module is being used for my entire website, which I do not want.
I tried using the tag to define the module for ONLY the service, but couldn't get it to work. I tried setting the path to both "WebServices/Registration.svc" as well as just "WebServices".
Is there a better way to register an httpModule to affect ONLY a WCF webservice within a website project?
TIA for any assistance!

asp.net mvc 2 web application inside a Web site?

I have a Asp.Net Web Site deployed as a WebSite inside IIS 7.5.
http://localhost/WebSite
Then I have a second Asp.Net MVC 2 web application which is deployed as Sub Application inside the above WebSite. So the mvc aplication should work on the following Url.
http://localhost/WebSite/MvcApp/
The web site works fine but when I browse the mvc Url http://localhost/WebSite/MvcApp/
It gives following error.
HTTP Error 403.14 - Forbidden The Web
server is configured to not list the
contents of this directory.
UPDATE: I have got this working. The issue was that I was missing the Web.Config inside the Views folder in the Asp.Net MVC 2 application.
You might need to create a virtual directory for the ASP.NET MVC application which will be associated to its dedicated application pool.
I know I had the same problem some time ago. In my case the two applications ran a siblings, not one inside the other. The problem was the web.config in the root directory (above the two sites) conflicting with the the web.config in the seperate sites. I solved it by just deleting the root web.config (since I have nothing running in the root.
So my advice (I know it's definately not a solution) is to check for conflicts in your web.configs.
Is you Asp.Net MVC site running ASP.NET 4.0? If so, make sure the app pool for that MVC site is setup asp ASP.NET 4.0 and not ASP.NET 2.0.
From within IIS Manager, you can right click any folder in the tree to be converted to an application. Have you tried it?
It sounds to me like the mvc routing module is not executing on your requests. You might want to check to make sure that not only is the web.config in your base web application not loading a module to supersede the routing handler, but that the web.config for your mvc application is handling routing properly. Take a look at this article for a rundown of the dependencies for routing and how it is configured internally within iis.

Publishing an ASP.net Webservice

I have a solution with a number of projects in..
One of these projects is a web application, another is a web service.
The web app references the web service, and uses the methods in there.
In production, the web application will be hosted on one server, while the xml web service will be on another.
My question is, how do i deploy this?
I've "published" the application to the correct server, however what do i do with the xml web service? and how can i configure my web application to point to the other server, rather than try and use localhost....
You generally won't leave your web service proxy classes with their default URL in production code. You can configure the production web service url in your web.config class and then have something like
MyWebService svc = new MyWebService();
svc.Url = WebConfigurationManager.AppSettings["MyWebService"];
Something along those lines should get you what you need.
When you add the proxy to you web application, you can set it to be dynamic url. This will create a config file entry that can be set during your deployment. Click on the Web Reference in the Solution Explorer, change the URL Behavior from Static to Dynamic from properties. An app.config file will be created with a key.

Resources