Is there a way to use proxy concept with NancyFx? I mean, I would like to access a service and record the response in my Nancy application (as proxy), either on a JSON file (similiar to wiremock) or in memory (similar to mountebank)
Thanks in advance.
Have you considered WireMock.net as it has a proxy feature and saves the results to json files.
Towards the end of this article is an example of using the proxy feature of wiremock.
You could certainly write a load of code to log the request and response, and use one of the standard web clients to pass the request back to the service, but Nancy has no built in system for this - Nancy is an MVC web framework, not a proxy server.
Perhaps you need something more along the lines of Nginx?
Related
I was recently assigned the task of creating a login page for my company and they're requiring that I use angularjs for the client side application.
The authenication services are asp.net web services that have already been coded, and return xml because of another service that also uses them.
I notice that AngularJS wants JSON data for it's return value.
I need a way of using AngularJS http methods get and post that will work with data from and to the web server using SOAP. My recent attempts have consisted of trying to get the xml back and then convert it to json on the client side.
Converting on client-side can potentially have problems and so I would prefer to keep all conversations on the server-side.
My solution would be something like have all my web services working as normal. Then have one web service that can take another method in as a parameter and call that method in code and return a json string.
Can anyone give me some input on this. My reason behind not wanting to simply change the web services to return json is because other applications use this service and are expecting xml, also there are more than 1000 web methods in place.
I may have found a solution I am going to work towards. However, if any viable options are still available that would simply add a new method to the list of web methods that would be great. Talking with the developer that wrote all the web services I will need to be using it would be simpler to convert the xml to json on client-side. I am also looking into some angular modules that people have written for get, post for soap services.
Found here
After lots of digging around the best option for me is to use this code Here. I can make the call easily and once I get the xml back just do angular.fromJson(angular.toJson(response)).
If ASP.NET WebAPI is used on the server side it may be sufficient to add an Accept header with the value application/json to the HTML request. It tells the server to return JSON instead of XML.
As a quick run-through, i've got the following scenario
Website which hosts c# web api services
each webapi takes a 'request' message type and returns a 'response' message type
Also a winforms client app which has its own repository that consumes the webapi services for its own use.
Is it good practice to put the request/response messages in a shared library which will be used by both the website, and by the client app bearing in mind if i update the webapi on the website, it could get out of sync with the distributed client apps, and may break functionality for them until they upgrade to the latest version.
thanks for any suggestions.
If you cannot force your clients to update to the latest version, I would create a new endpoint with a corresponding shared library for each breaking change.
http://yourservice/api/v1/GetXY
http://yourservice/api/v2/GetXY
http://yourservice/api/v3/GetXY
....
And you could set up monitoring to see which old/obsolete endpoint is not in use anymore and turn it off if you want.
After searching the entire day about what I should use, I'm not sure what option would be best for my needs so I hope someone with more experience could help me out.
I have a winforms application (c#) and a ASP.NET MVC 4 web application (c#).
I wish to connect these, the goal is to send and receive data from the database which I use in the MVC 4 project, but from within the windows forms application. The data I send from the windows forms application to the database, is then used by the MVC 4 web application.
I am entirely new to web services / Web Api's so I can't really decide what option would be best. Any help would be much appreciated..
If you already created MVC4 project then you can add actions to any controller
and return JSON data like below :
public JsonResult GetCategoryList()
{
var list = //return list
return Json(list, JsonRequestBehavior.AllowGet);
}
or you can create new project of MVC4 and select WEBAPI template . It will create webapi project for you .It will create with example .so it will easy for to create webapi.In webapi it return data automatically convert to xml and json as per request
The WCF Web API abstractions map to ASP.NET Web API roughly as follows
WCF Web AP -> ASP.NET Web API
Service -> Web API controller
Operation -> Action
Service contract -> Not applicable
Endpoint -> Not applicable
URI templates -> ASP.NET Routing
Message handlers -> Same
Formatters -> Same
Operation handlers -> Filters, model binders
Other Links
If you have an MVC 4 App already, it would be better to use Web API (RESTful service)
I assume you have some knowledge in building REST API (understanding of POST, PUT, UPDATE stuff)
It is simple in configuration and usage. All what you need actually is to create a new controller like:
class MyApiController: ApiController {
public Post(SomeClass item) {
....connect to db and do whatever you need with the data
}
}
You'll also should configure routing for Api.
And then in your winForms app you can simply use HttpClient class to perform api call.
HttpClient aClient = new HttpClient();
// Uri is where we are posting to:
Uri theUri = new Uri("https://mysite.com/api/MyApi");
// use the Http client to POST some content ( ‘theContent’ not yet defined).
aClient.PostAsync(theUri, new SomeClass());
Take a look at some implementation details right here:
Web Api Getting Started
Get started with WCF is not so easy as with Web API.
Given the tags you've used, my guess is that you're deciding between SOAP Web Services and WCF. Given these two, I say to go WCF. SOAP web services (as implemented in Visual Studio) are the older technology; still serviceable, but WCF can do everything an older SOAP service can do (including look exactly like a SOAP service) and more.
If you have a web service that connects your web server to your database server (these two things should be on different machines; your web server is exposed to the world by necessity, while your DB server should be locked down like Fort Knox), I see no reason why you shouldn't use that same service as-is for an internal WinForms application (using a LAN/VPN to access the service layer on the DB server). For a WinForms application that must access the data over the Internet, I would recommend reimplementing the service as a WCF service supporting secure encrypted data transfer. You can also set up the service endpoint to only accept HTTPS connections, and thus simply run your existing service through SSL/TLS.
What you choose will primarily depend on how much time-resources you can commit to resolving the problem; moving to HTTPS is a fast fix requiring little if any code changes, while reimplementing in WCF will take more time but will allow additional security measures beyond a simple secure tunnel.
Or something lightweight like Nancy: http://nancyfx.org/
We had some issues with MVC4 WebApi stuff and ended up using ServiceStack on the server side JavaScript/AJAX for web clients and RestSharp for thick clients.
One of our specific issues was the inability to auto generate documentation, significant performance differences, and better support for unit/integration testing.
Rather than advocate specifically WCF, I'd recommend WCF Data Services or OData, with the stipulation that you'll need to secure it. If you go for pure WCF, you'll see that you'll end up creating a lot of code to handle retrieving the info from a database, and then sending that information right back out to your clients. It doesn't sound that bad, at first, but after about 30 entities in a database, you'll quickly grow tired of a pure WCF solution.
OData is great, it uses Entity Framework, and it quickly opens data manipulation for an existing database or one you are going to make. It will save you a ton of development time, if you can make your service secure. The format of the data response is flexible. There are plenty of client libraries ported for other programming languages as well.
The steps for securing a service are pretty simple. Always deploy to https. Any login or registration methods , need to be post methods, that return a token (Encrypted value), or a unique secret that can be encrypted and sent back for any subsequent requests. It's better to use the token, and have an expiration on the token.. because otherwise both your service and your app whether mobile or desktop, need to have a shared encryption / decryption method.
As a tester, i was asked to test a web service via C#. I've no idea how to use C# directly to send data to Web Service. Could you please give some samples about it? BTW, please do not use the proxy method.
Thanks
Sut
I'd recommend using SOAPUI if you are trying to test SOAP web services directly. Trying to call them using HTTP requests and then parsing the resulting SOAP is going to be quite a chore if you have to use C# and not use the imported proxies.
Note: You'd be much better of if you talk to whoever asked you to do something... instead of asking strangers.
In most cases call to web service is simple HTTP POST or GET. There are plenty of ways to perform it directly - i.e. "How to: Send Data Using the WebRequest Class" ( http://msdn.microsoft.com/en-us/library/debx8sh9.aspx).
And response from web service is generally XML - again plenty of classes to read including XmlDocument and XDocument.
Before I venture down the path of creating one, I was wondering if anyone knows of a utility program which will take the REST Help page of a WCF Rest Service and create the relevant Client for C# consumption.
Similar to what svcutil.exe does for WCF Services or what wsdl.exe did for web services but for WCF REST Services
Kind Regards,
Andrew
EDIT Some more detail:
Please see this link: http://msdn.microsoft.com/en-us/library/dd203052.aspx
In the restful service using the WCF Rest Starter Kit Preview 2, they supply types which will be serialized. But My intention is be able to create clients form the help page which describes schemas. Clients could then be created for C#, JavaScript, ActionScript etc.. shearly as a strongly typed version of the restful service, not a requirement or necessity. It is a program or uitlity I am wondering exists which does this
I think you might be looking for the WebChannelFactory. It can generate a channel class based on a WCF-attributed REST interface.
Well, there will not be any use even if you would like to abstract. ALL Rest services can use HTTP verbs like GET, POST, PUT, DELETE
So, basically what your client can have is only a static class which can accept the end point, network credentials, a name value collection which needs to be passed and the verb to use.
This would be more of a utility class rather than a client.
I don't remember seeing WSDL or some contract based on which we can write clients for the REST services.
I hope you don't spend too much time basing your code on the current help page of a pre-release piece of code. Are you even sure this help page provides all the information you would need to produce clients?
Also, have you seen Prerelease 2 of the WCF REST Starter kit yet? If no, go look. There's new client-side technology in there.
Why would you create clients for a RESTful service? You don't need one - you just need to be able to initial HTTP requests. If you would like to call the same operations via SOAP or some other method then create a new endpoint for the service and a new contract and expose mex for it so that svcutil can consume it.