Running SOAP and RESTful on the same URL

房东的猫 提交于 2020-01-03 20:03:21

问题


Say we have a website that responds to a host header "kebab-shop.intra.net"

Is is possible to have both SOAP and RESTful in this URL?

That is, both of these are handled within the deployed code.

  • kebab-shop.intra.net/takeaway.asmx
  • kebab-shop.intra.net/kebab/get/...

I've been told this can't be done, without much explanation. Like this answer. This could be, I'm a database monkey, but I'd like some thoughts on what options I do or don't have please.

Thoughts so far

  • Separate host headers eg add kebab-shop-rest.intra.net
  • Separate web sites

Ideally, I'd like to have one web site, one URL domain name, one host header. Zero chance?

This is IIS 6 with .net 4. And we have some large corporate limitations that mean we are limited to a zip file to drop into the relevant folder used by the web site. This is intended to allow our clients to migrate without incurring the large corporate support, infrastructure and deployment overhead. The co-existence will only be for a month or three.

Edit: I'm asking because I'm not web developer. If my terms are wrong, this is why...

So... I want both SOAP and REST on kebab-shop.intra.net on IIS 6 without complexity.


回答1:


That is, both of these are handled within the deployed code.

* kebab-shop.intra.net/takeaway.asmx
* kebab-shop.intra.net/kebab/get/...

Yes, that should definitely be possible. If you have a single WCF service, you could easily expose two separate endpoints for the same service - one using e.g. basicHttpBinding (roughly equivalent to ASMX), and another with webHttpBinding (REST).

The complete URL's must be different - but the first part can be the same, I believe.

If you're hosting in IIS6, you need one virtual directory and that will partly dictate your SOAP endpoint - it will have to be something like:

http://kebab-shop.intra.net/YourVirtDir/takeaway.svc

(or: http://kebab-shop.intra.net/YourVirtDir/takeaway.asmx if you insist on using an ASP.NET legacy webservice).

and the REST endpoint can live inside the same virtual directory and define URI templates, e.g. you could have something like:

http://kebab-shop.intra.net/YourVirtDir/TakeKebab/gbn

or similar URL's.

However: checking this out myself I found that you cannot have both service endpoints "live" off the same base address - one of them has to have another "relative address" associated with it.

So either you add e.g. "SOAP" to your SOAP endpoint

http://kebab-shop.intra.net/YourVirtDir/takeaway.svc/SOAP/GetKebab
http://kebab-shop.intra.net/YourVirtDir/TakeKebab/gbn

or you add something to your REST service

http://kebab-shop.intra.net/YourVirtDir/takeaway.svc/GetKebab
http://kebab-shop.intra.net/YourVirtDir/REST/TakeKebab/gbn



回答2:


I don't see a reason why you can't. Typìcally your SOAP endpoints will be one specific URLs per service, whereas for resources exposed via REST you will have one URL per resource (following 'URL patterns').

Example URLs for SOAP:

http://kebab-shop.intra.net/soap/service1    
http://kebab-shop.intra.net/soap/service2

Example URL patterns for REST:

http://kebab-shop.intra.net/rest/{resourcetype}/{id}/

e.g.: http://kebab-shop.intra.net/rest/monkeys/32/

etc...



来源:https://stackoverflow.com/questions/4901293/running-soap-and-restful-on-the-same-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!