C# - Create .NET Web Service Fully Contained In .svc File?
Dec 3, 2010
Is it possible to create a "drop-in" web service? What I would like to do is create an .svc file that can be placed into a web directory on IIS and accessed (and executed) via its URL, without having to install any other files and without changing any configuration files.I am investigating a possible security problem in a web application that allows uploading .svc files. If it is possible to upload and then execute an .svc file, this would be a big security problem for this application. Unfortunately I am not a .NET developer, so I am probably missing a lot of things here.I know that it is possible to put the service interface and implementation straight into the the .svc file after the "Service Host" directive. Here is my .svc file:
<%@ ServiceHost Language = "C#" Debug = "true" Service = "EchoService" %>
public interface IEchoService
{
[code]....
Now when I access http://localhost/test1.svc I get an exception from .NET: Service 'EchoService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element. I understand that normally you are supposed to configure web service end points in web.config or app.config file. From some Googling I have also learned that it is possible to configure endpoints programmatically by defining your own ServiceHost and ServiceCodeFactory. I have found some examples, but couldn't get them working.I would really appreciate if somebody can either tell me "No, what you are trying to do is impossible, because..." or show how I can add the necessary code to the example above to have an executable service.
Update: using Josh's suggestion I finally got it working. See my answer below for the working code.
I'm want to make a BLOG site and that should be fully Dyanmic.Means from Questions to answers all should be fully Dyanmic but need admin approval to post.can you share some links where i can get more about this.
In ASP.NET I'd like to create a link which points to a specific Uri and send this link in an email to a user, for instance something like http://www.BlaBla.com/CustomerPortal/Order/9876. I can create the second part of the Uri /CustomerPortal/Order/9876 dynamically in code-behind. My question is: How can I create the base Uri http://www.BlaBla.com without hardcoding it in my application? Basically I want to have something like:
http://localhost:1234/CustomerPortal/Order/9876 (on my development machine) http://testserver/CustomerPortal/Order/9876 (on an internal test server) http://www.BlaBla.com/CustomerPortal/Order/9876 (on the production server)
I have a WSDL, and I need to write this web service. (I am not the client, I am the provider of this service) Is there any tool and/or best approch to create this Web Service?
Scenario is I have a application relative url like "~/path/to/page.aspx?query=string". I need to programatically create a web request to that page and currently using WebRequest.Create. The problem is WebRequest.Create requires a fully qualified url including the protocol/domain/port etc.I have access to the current Request.Url object but there doesn't seem to be an easy way to get just the base url keeping the protocol (HTTP vs HTTPS) as well as any port numbers as well as the path to the applicationI mean all the info there, so if need be I could just take all the parts and combine them but it seems like it might be error prone and it would be great to have something built-in that's well tested to do the job. Page.ResolveUrl gets me almost there, but it's missing the protocol and the domain/port.
I developed a web service in VS2010 on my local machine, wrote a consumer of it also locally, and that all works.
I copied the dll and the asmx file to our server, and I am getting an error when I try to invoke it from a browser (also still on the server machine) to make sure it correctly exposes its web methods, but it is not, it is saying "Could not create type 'Service'". That error comes from this line:
Line 1: <%@ WebService Language="C#" CodeBehind="~/App_Code/WarrantyDuplicate.cs" Class="Service" %> There other web services in the same folder on the server that all work fine so I don't believe it's an IIS setup thing.
This is my first web service in C# and when I created it in VS I did think it odd that the code behind file went into App_Code (as you can see from the line in the asmx file) and is just named dot-cs rather than asmx-dot-cs. But since it worked fine locally, I wasn't sure that mattered.
How to create an instance of web service without adding web service reference? How to identify the server address/name where the web service is hosted from C# code?
I have a requirement to create a XML file from sql server data.I need to schedule this job to run at specific intervals of time.I don't know, if I could do with Reporting services.I would like to know, if it's possible with Sql server reporting services? how to do that.
i want to create a web service which consists of CRUD operations Create, Retrieve, Update and Delete. creating web methods on insert and update operations.
I am using JQuery & JSON (POST) to call webmethod. However I can call only webmethod located at aspx file but not in asmx file Below are sample codes
CustomValidate.asmx Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel Public Class CustomValidate Inherits System.Web.Services.WebService 'ACCESS VIA JSON <System.Web.Services.WebMethod()> _ Public Shared Function AJAX_Test(ByVal date1) As Boolean... Return True End Function End Class Javascript: JQuery JSON function isDates(source, arguments) { var isValidDate; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "CustomValidate.asmx/AJAX_Test", data: '{date1: "' + arguments.Value + '"}', dataType: "json", async: false, success: function(result) { isValidDate = result; }, error: function(httpRequest, textStatus, errorThrown) { alert("status=" + textStatus + ",error=" + errorThrown); } }); arguments.IsValid = isValidDate; }
It always return javascript undefined error. But if I put the AJAX_Test webmethod in aspx page and replace the url: "CustomValidate.asmx/AJAX_Test" to "mypage.aspx/AJAX_Test". It works fine.
I m accessing another application by consuming webservice of that application. I m sending file to store and retrieving file from other dabatase. Web service is the only to access another application.Now, I want to delete the file using the same web service where I stored that file in the another database.I m getting exception and I m unable to figure it out.
I've got some textboxes in a panel, that I want to disable client-side upon radio button selection. I've got it basically working - but I discovered that javascript's control.disabled = true still allows the user to type in the textbox. So I've moved on to control.readOnly (in addition to disabled) - that seems to give the result I want.
Problem is, setting readOnly at the panel level doesn't seem to propagate down to the contained controls (the textboxes). I still have to call textbox.readOnly directly in order to get the no-typing-allowed result I need. And this makes the whole panel-concept useless for me in this instance.
Am I doing it wrong somehow, or is this just the way panels work (i.e., can only make textboxes readOnly by directly manipulating its property)?
I would like an UpdatPanel to update it's content once a button is clicked - this button is contained within a UserControl placed on the webpage.However, I cannot just simply reference it using the AsyncPostBackTrigger's ControlID property, because the button is not situated directly on the webpage.
I have an update panel within it i have my activeX control, below it i have a dropdown that you make a selection from, once you make a selection im trying to pass in different paramters, which really are just the source of the control, since everything else will be the same.. but when i make a selection, the control disappears..
If i remove the update panel and make a selection the control is still visable on the page, at the moment, i dont have much setup, im just trying to get the page layout and framework setup adn working, then i can start plugging in my datasource so actual data is being passed in..
I do have a trigger associated with the updatepanel, but with or without it it still causes the control to disappear..
Just to be clear, it disappearing when i view the page in my browser and make a selection, not within VS. Whats weird is that ONLY that control disappears, the rest of the controls on the page stay visible, the dropdown and buttons.