Please help me to find a solution for the titled problem. I've a Webservice developed in C# with few action. For each action there are two XSDs one for request and another for response. I want that when service is invoked on the client side these XSDs shold get exposed into the wsdl document. Any help to achieve this is most welcome.
You can make changes to webMethods? If yes, you can decorate the methods by the attribute XmlAttributeInclude.
This should include the declaration of XYZ and ABC types in the WSDL of your Web service. I hope I have understood your needs.
[XmlInclude(typeof(XYZ))]
[XmlInclude(typeof(ABC))]
[WebMethod()]
public XYZ Foo(ABC data)
{
return new XYZ();
}
Related
I have a ASp.Net WebApi and I add the DelegatingHandler for modify the requestUri.
I tried some examples without results, It is possible?
I Would like to encrypt (client) Decrypt (WebApi) part of the URL.
In the WebApi exists the controller with the route:
api/employee/getInfo/{name}/{lastname}/{date}
From my web client I do the GET to the URL:
http://localhost/api/employee/getInfo/jhon/smith/010525
In the client interceptor I'm encrypt the last part of the URL, (base64 for the example)
http://localhost/api/employee/getInfo/amhvbi9zbWl0aC8wMTA1MjU=
Then in the SendAsync from DelegatingHandler that I want is decrypt the last part to
restore to the original URL to the webapi executes the proper webapi function.
thanks.
I did the next:
I added an additional route to my controller
[Route("api/employee/getInfo/{payload}")]
in the webapi
in the client interceptor change the original call
http://localhost/api/employee/getInfo/jhon/smith/010525
to
http://localhost/api/employee/getInfo/EncryptedInfo
finally in the DelegatingHandler
decrypt and convert to QueryString
http://localhost/api/employee/getInfo?name=jhon&lastname=smith&date=010525
I don't know if it's the correct way but for the moment is working.
If somebody have a better and correct solution please share.
thanks.
Good evening,
I have one scenario that i have a httpGet method with complex object and needs to call this from another .net project by passing Json object., Below is the sample.
APIController
[HttpGet]
[Route("GetName")]
public async Task<string> GetName([FromUri]MyClass myClass)
{
return myClass?.MyName?.ToString() + "this is my method result";
}
Postman
http://localhost/api/NameSearch/GetName?MyClass={'MyName':'TestName'}
I know this is very easy to achieve if i change the action from httpGet to httpPost., But this has been told that i am not doing any update within my api, so i should not use the Post. Also i should not be sending this as individual parameter like ?MyName=''&MySecondParam='',etc., The request has to be passed as single Json object to the API.
Please kindly suggest if there is any option. I tried the above ?MyClass={'MyName':'TestName'} which is not working.
Thanks in advance.
experts, I would log every incoming http request call with payload into database.
I checked there would be 2 approaches.
use filter or interceptor.
I feel filter is so easier for me to implement.
what would be best approach for my purpose?
please kindly advise.
thank you very much!
if you have a need to do something completely generic (e.g. log all requests), then a filter is sufficient - but if the behavior depends on the target handler or you want to do something between the request handling and view rendering, then the HandlerInterceptor provides that flexibility.
But anyway, just do the way which make you feel easily and simply.
Note:
Interceptor work in spring application context
Servlet work in web context
Use Spring AOP. Use any advice according to your needs.
#Aspect
#Component
public class Test {
#Around("#annotation(mapping) ")
public Object preAuthUserPersmission(ProceedingJoinPoint joinPoint, RequestMapping mapping) throws Throwable {
Object[] parameters = joinPoint.getArgs();
// Your actions on the input parameters
return joinPoint.proceed(joinPoint.getArgs());
}
}
I am using ASP.NET MVC 4 WEB API to create a Restful API service. This is my first go at it, so if you feel I am taking a wrong approach please feel free to correct.
I want to create a rest API (only & not a website, the consumer of the api can decide where they want to consume it), in the past I have used Restful WCF service to achieve this.
I have created a new ASP.NET MVC 4 Web Application and chose the WebAPI project template. I have added a controller class 'CatalogueController.cs' the purpose is on Get() operation I want to return the Catalogue list. The CatalogueDo contains only one property 'Service' of type string.
[System.Web.Http.HttpGet()]
public HttpResponseMessage Get()
{
return Request.CreateResponse(HttpStatusCode.OK, Catalogue);
}
When I run the application the browser loads with the URL http://localhost:5502/ resource not found, if I add the controller name http://localhost:5502/Catalogue/ the browser pops open a notepad with,
[{"Service":"Exchange"},{"Service":"Holidays"}]
The data is correct but
the browser keeps showing resource not found and after my request has been served the URL changes to http://localhost:5502/.
Question,
Am I doing something wrong? Should the response that pops up in the
notepad not be shown as xml in the browser it self?
Why does the controller name get removed from the URL once the request has been served?
Is it at all possible to invoke this REST service from Excel or Power Pivot?
In my asp.net mvc 2 app, I'm wondering about the best way to implement this:
For every incoming request I need to perform custom authorization before allowing the file to be served. (This is based on headers and contents of the querystring. If you're familiar with how Amazon S3 does rest authentication - exactly that).
I'd like to do this in the most perfomant way possible, which probably means as light a touch as possible, with IIS doing as much of the actual work as possible.
The service will need to handle GET requests, as well as writing new files coming in via POST/PUT requests.
The requests are for an abitrary file, so it could be:
GET http://storage.foo.com/bla/egg/foo18/something.bin
POST http://storage.foo.com/else.txt
Right now I've half implemented it using an IHttpHandler which handles all routes (with routes.RouteExistingFiles = true), but not sure if that's the best, or if I should be hooking into the lifecycle somewhere else?
I'm also interested in supporting partial downloads with the Range header. Using
response.TransmitFile(finalPath);
as I am now means I'll have to do that manually, which seems a bit lowlevel?
Many thanks for any pointers.
(IIS7)
I think having a custom handler in the middle that takes care of this is exactly how you should be doing it.
TransmitFile is the lightest-weight programmatic way to serve a file that I am aware of.
However, you might not need to write your own HttpHandler. You can use the MVC handler and just dedicate a controller action to the job. Something like:
http://storage.foo.com/Files/Download/SomeFileIdentifier
...routing to...
public FilesController
{
public ActionResult Download(string id)
{
//...some logic to authenticate and to get the local file path
return File(theLocalFilePath, mimeType);
}
}
The File() method of controller uses TransmitFile in the background, I believe.
(PS, If you want shorter URLs, do it via custom routes in global.asax.)