Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I want to do what a SoapExtension can do if you provide a custom SoapExtensionAttribute... but to do it for every SOAP call without having to add the extension attribute to dozens of WebMethods.
What I'm looking for is any extension point that lets me hook in as:
void ProcessMessage(SoapMessage message)
without needing to individually decorate each WebMethod. It's even fine if I have to only annotate the WebServices - I only have a few of those.
There is a configuration property, soapExtensionTypes that does this, but affects all web services covered by the .config (all of them in the same directory or a sub-directory as the .config)
Related
I started using servicestack javascript client for our application. Our webservices uses servicestack with custom routes (api.geni.us/v1/groups/list?format=jsv). The problem is that on the current client have no way to indicate that we want to use the query parameters (format=jsv) its currently set to always use the standard route(jsv/reply). Right now the only option we see is to inheriting from the client and customize the constructor but we are wondering if there is a prescribed way to do that before we go into implementing a version specific to us.
We're setting up a bunch of json web services in ASP.NET which is served as .ashx (custom handlers) files. An example would be:
/mobile/json.ashx
We'd like to implement some form of versioning as well as to not break apps which has not upgraded. So we led down this path:
/mobile/json.ashx?v=1.0
Now, of course we have have a switch statement in our custom handlers to manage the differences between api version but this doesn't sound like a very maintainable solution to me.
What are the best practises for this kind of set up and what options are available for version control?
Thanks
Placing the version in the query parameters (that is, after the ?) suggests to the user that each endpoint is individually versioned. I would avoid this.
If your web service is structured such that there are larger logical units that are being individually versioned, then I would go with something like this:
/api1/1.0/some/endpoint
/api1/1.1/some/endpoint
/api2/1.0/some/other/endpoint
/api2/2.0/some/other/endpoint
...
The version portion of the path comes directly after the thing which is being versioned. This suggests to the user that everything underneath /api1/1.1/ is version 1.1 of API 1 and everything underneath /api2/2.0/ is version 2.0 of API 2.
If someone entirely omits the version portion of the path, the latest version should be implied. So /api2/some/other/endpoint would map to, say, /api2/2.0/some/other/endpoint.
If you're using ASP.NET MVC, all of this can be accomplished very easy using route configuration in the RegisterRoutes method in Global.asax.cs. For example:
routes.MapRoute("api1/1.1", "api1/1.1/some/endpoint",
new { controller = "Api1_1_1", action = "SomeEndpoint" });
where you have a controller class Api1_1_1 with method SomeEndpoint.
I need to create a backing service for a jQuery token input field control.
Our application consists of controls for a (third-party) DotNetNuke module called SimpleWrapper. The way this module works is that it provides a lightweight but not very flexible way of displaying regular ASP.NET user controls on a DNN page. The caveat is these are .ascx controls, not .aspx pages.
I'm mostly at a loss at which of the various technologies available to use. I looked at ASMX services but those mostly seem tailored to producing generated JavaScript proxy code. I need to be able to:
mount the service at a static URL
have it accept a single string parameter
have it produce JSON in a specific, but very simple format
I don't really need strong integration with ASP.NET, like being able to respond to a postback or some such. I'd also prefer something deployable just by adding a file, without having to edit configuration files. What would be a straightforward way to spit out a chunk of JSON in such an environment?
WCF (I think starting with version 3.51) has a nice "zero config" feature that integrates easily with IIS. All you have to do is
create a JSON aware interface & service
create a simple .SVC file in the IIS site.
You don't need to mess with funky .config files :-)
Example .SVC file:
<%# ServiceHost
Service="MyNamespace.MyService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Example interface & service implementation, something like this:
public class MyService : IMyService
{
public string Test(string text)
{
return text; // whatever
}
}
[ServiceContractAttribute(Namespace="http://schemas.myservice.com")]
public interface IMyService
{
[OperationContractAttribute]
[WebInvokeAttribute(UriTemplate="Test", // change this accordingly
ResponseFormat=WebMessageFormat.Json, // change this accordingly
RequestFormat=WebMessageFormat.Json, // change this accordingly
BodyStyle=Wrapped)]
string Test(string text);
}
Here is an extra cool link about all this: WCF Web Services The Easy Way.
JSON Exposed thru Restful Service
This Link will guide you step by step on how to do what I believe to be what you are looking for has actual code sample
I don't see why WCF Web services or ASMX Web Services are not suitable for what you say you need. Personally, that's the way I'd go (choosing WCF over ASMX).
I looked at the link DJ KRAZE posted and it uses an HTTP Handler plus uses some third party Javascript serializer (one extra dependency that isn't really needed since you have JavascriptSerializer if needed).
We have a homegrown framework that might be useful
to implement REST based webservices.
It is a .net c# project, used in a webapplication.
What it is used like: inline substitution of template 'tags' with dynamic content. sample tag: {{recentposts window=7 max=10}}
What it does: parsing 'tag' to command with (checked) parameters, invoking a
handler configured to handle the command and return data, transforming the data with xsl,
substitute {{...}} with the result.
I have a hunch that this could be reworked to create some form of REST based
services, parsing an url to a command with parameters, invoking a handler etc.
and writing the result to http response.
As an alternative to reworking I'm looking for smth
that might be useable instead, out of the box.
What are mature (open source) frameworks that could be used?
It has to provide a http facade, to do the REST stuff easily, and besides provide an API,
a way to bypass this facade, allowing command objects to be created, having all the invocation and transformation done and instead of writing to http response to some stream.
How about ServiceStack?
Quote from the webpage:
A modern, code-first, DTO-driven, WCF replacement web services framework encouraging best-practices for creating DRY, high-perfomance, scalable REST web services
...and an "overview" slideshow.
I use EasyHttp to work with REST base serices, it works easily with JSON and XML services and also supports working with retrieved object as a dynamic object. Very easy to plug and use and you don't have to worry about Http Request/Response anymore.
I think it may be worth taking a look at OpenRasta
https://github.com/openrasta/openrasta-stable/wiki
The OpenRasta project is a web framework that les you build web
applications as simple as
public class Home { public string Get() {
return "Hello world"; } }
It's really nice to use and easy to get started with
I've currently written code to use the ServiceContractGenerator to generate web service client code based on a wsdl, and then compile it into an assembly in memory using the code dom. I'm then using reflection to set up the binding, endpoint, service values/types, and then ultimately invoke the web service method based on xml configuration that can be altered at run time.
This all currently works fine. However, the problem I'm currently running into, is that I'm hitting several exotic web services that require lots of custom binding/security settings. This is forcing me to add more and more configuration into my custom xml configurations, as well as the corresponding updates to my code to interpret and set those binding/security settings in code.
Ultimately, this makes adding these 'exotic' services slower, and I can see myself eventually reimplementing the 'system.serviceModel' section of the web or app.config file, which is never a good thing.
My question is, and this is where my lack of experience .net and C# shows, is there a way to define the configuration normally found in the web.config or app.config 'system.serviceModel' section somewhere else, and at run time supply this to configuration to the web service client?
Is there a way to attach an app.config directly to an assembly as a resource or any other way to supply this configuration to the client?
Basically, I'd like attach an app.config only containing a 'system.serviceModel' to the assembly containing a web service client so that it can use its configuration. This way I wouldn't need to handle every configuration under the sun, I could let .net do it for me.
Fyi, it's not an option for me to put the configuration for every service in the app.config for the running application.
Any help would be greatly appreciated.
Thanks in advance!
Bryan
Create a custom class deriving from
ChannelFactory.
Override the protected
CreateDescription method. In the
override, you need to...
Call base.CreateDescription().
Read in your custom configuration.
Create a custom ServiceEndpoint based
on your configuration. Don't forget
the bindings, behaviors, etc.
Return that custom ServiceEndpoint.
More details HERE
The following couple links talk about loading WCF Configuration settings from config files other than the app.config. May be what you are looking for but not certain.
http://blogs.msdn.com/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx
http://weblogs.asp.net/cibrax/archive/2007/10/19/loading-the-wcf-configuration-from-different-files-on-the-client-side.aspx
Are your proxy classes deriving from ClientBase<T>? If so, then there is a constructor that accepts a Binding and an EndpointAddress. You should be able to use those instead of the corresponding configuration data.