WCF servicehost codebehind - wcf

I have a website project and in that I added a .svc file with the following details-
<%# ServiceHost Language="VB" Debug="true" Service="Communication" CodeBehind="???" %>
Here am not sure what should I put in for "CodeBehind". As I have put all my service contracts and their implementations in another project and I added that project as a reference to this website. Is this allowed? Or Do I need to have the Codebehind files only in the App_Code folder under website project?
Please suggest if there is a way to specify the CodeBehind file other than placing that in App_Code folder.
Thanks in advance
Sai

you don't need a codebehind I don't believe. Just specifying the service is enough, although you need to specify the full namespace of the class which implements the service.
According to this example, you should be fine doing this if the class is in another referenced assembly, in which case you don't need the language bit either, only the service part.
In the example on MSDN they don't use it.

Related

What is the ASP.NET Core convention for static, non-MVC pages?

I'm converting my website from Web Forms to .NET Core. I don't want to change the directory level of various files, e.g.:
MYDOMAIN.com/FAQ.html
MYDOMAIN.com/Privacy.html
By using the UseStaticFiles() middleware, I can place these in the wwwroot folder and they will be served as is. However, I don't know how to apply a Layout page with my website theme to those files since they're outside of the MVC framework.
I'd like to leverage the Layout files and MVC framework by using .cshtml files, but I'm also trying to avoid the extra controller directory that's imposed on the URL:
MYDOMAIN.com/home/FAQ.html
MYDOMAIN.com/home/Privacy.html
Maybe this is short-sighted, but how do developers handle this?
And actually, my existing files are .aspx at the moment, not .html files so that adds another level of confusion as to what the convention is for migrating to .Net Core. Should I use any .aspx files anywhere in the project or should they all be converted to .cshtml / .html files? Or something else?
I have successfully implemented a solution, but it's kind of a hack. I add controllers for each static page, for example I created both a FAQController.cs and PrivacyController.cs.
Each controller has only Index() actions so that they can take advantage of _Layout.cshtml and _ViewStart.cshtml.
It seems like a roundabout way to go just to move the following up one level e.g.
MYDOMAIN.com/FAQ
MYDOMAIN.com/Privacy
but it works.

Upgrading a Web Reference in a VB.Net Class Library Project

Our vendor has upgraded their SOAP Offering and we need to reference another WSDL file and change the url for the .asmx file to the newer versions.
What is the best way to do this with minimum breaking of the code?
It was referenced with a namespace as is typical.
Should I delete the existing web reference and add the new one using the same name?
Or should i change the 'web reference url' url to the new one and simply update it?
Any ideas / solutions would be greatly appreciated
Here was my solution:
I changed the 'Web Reference URL' of the folder in Web References to the new WSDL
I then right clicked the folder and clicked 'Update Web Reference'
And it changed all of the files that were expected

WCF Global.asax events not firing

I have built a WCF application which has Global.asax file. I have added AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)
on top of service class and added
into web.config as well.
Global.asax Application_Start event fires when debugging the application but when it deployed in the IIS7 its not firing.
Any help or idea?
Thank you.
If you make a request to your app does the "Application_Start" fire then? I don't believe it will be started until the first request is made.
Application level events only need proper naming to work. Is your codebehind class being designated in your Global.asax file?
<%# Application Inherits="YourNamespace.YourApplicationClass" Language="C#" %>
(Or)
becuase project is compiled first and then you have add or modify or changed location of global.asax.cs.
Solution :- Just remove debug folder. Clean project and then rebuild whole project.
Edit
When using the response object from an aspx page, its codebehind class or a
user control, the response object is directly available because all these
derive from the page object.
When using the response object in your own class, the object is not
available, but you can access it:
HttpContext.Current.Response. -> something
Take a look at here
Global ASAX - get the server name

How do I access RouteTable.Routes.MapHttpRoute?

I have a Web Forms app that I created a few months ago and I added a Web API controller. I tried to use the 'automatic' routing that I saw in a presentation recently, but all I got was a 404. Then I tried to add routing for the Web API controller in my Global.asax using MapHttpRoute, as I've seen in several tutorials. However, even after adding Imports System.Web.Http to the file, the project will not recognize RouteTable.Routes.MapHttpRoute() I have tried adding other namespaces and ensuring that I have all the necessary Nuget packages, but I still am unable to set up routing for the Web API controller. Does anyone have a recommendation of where to start?
If anyone has this same issue in C# read on.
I am also using a web forms app and set the routing through the Global.asax file. For me Intellisense was 100% correct and it would not build regardless. To get this to work I had to add the following using directives.
using System.Web.Http;
and
using System.Web.Routing;
Becareful not to use using System.Web.Http.Routing by accident. This wont work.
You should add the reference to System.Web.Http.WebHost assembly and make sure you have
using System.Web.Http;
Why ? MapHttpRoute is defined in two assemblies, in System.Web.Http:
public static System.Web.Http.Routing.IHttpRoute MapHttpRoute(
this System.Web.Http.HttpRouteCollection routes, string name, string routeTemplate)
Member of System.Web.Http.HttpRouteCollectionExtensions
and in System.Web.Http.WebHost
public static Route MapHttpRoute(
this RouteCollection routes, string name, string routeTemplate, object defaults);
First one is an Extension on HttpRouteCollection
Second one is an Extension on RouteCollection
So when you have a webforms app, your Routes are defined in a RouteCollection so you need the WebHost version.
Its because architecture allowing WebApi to be hosted also out of IIS. see Hosting WebApi
I found this thread, which indicates that IntelliSense apparently has a problem with this, but if you type something like the following, it will build and run:
RouteTable.Routes.MapHttpRoute("MyApi", "api/{controller}")
I've just created two new webforms apps (one using .NET 4, the other 4.5), did nothing more than add web api via nuget and it worked.
What version of ASP.NET is your app running in? If you're running ASP.NET WebForms 2.0/3.5 then it's not supported.
Here's a tutorial which demonstrates how to add Web API to your Web Forms app - http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-aspnet-web-forms
I have the same case, I solved by creating the api controller, when you add the
api controller VS will load all required refrences.

How to call WCF svc with URL and parameters as a GET

I have a simple WCF I am working on. I am used to .asmx files, web methods and SOAP but switching it up now. Got it working in .aspx page with a script manager and ServiceReference like below
<asp:ServiceReference Path="~/MyTest.svc" />
A coworker now needs it so he can call it in an iOS app (don't know much about that) but he says he needs to call it with the URL passing the parameters as a GET. Can you please tell me how to alter the .svc file to make that possible?
Many thanks!