问题
I have this scenario. Client requested us to have a WebService. I created a WCF Service. After we sent them our url to the web service description, client says
As it is we cannot consume a WCF service, can you publish it a web service?
Now i am wondering, they are asking me for a asmx... right? Is there any way that i can "offer" my WCF service as an asmx service so i don't have to rewrite the whole thing?
my first "solution" is to have an .asmx file calling my .svc files directly... i don't know. I havent tried but i am heading on that direction.
Any ideas would be highly appreciated.
Tony
回答1:
It is completely do-able. Just use an endpoint that exposes the service using basicHttpBinding or wsHttpBinding. The "file extension" of the URL doesn't make any difference to the client, only the content of the rerquest/response.
Here's a reference to another SO question: REST / SOAP endpoints for a WCF service
回答2:
It's very much possible.Follow the steps mentioned below and you'll be able to expose WCF service as ASMX endpoint.
- Add new web service file (.asmx)
- Now open the node of web .asmx file and delete .asmx.cs file
- Once .cs file is deleted. You will find wcfasasmx.asmx file.
I have WCF class name as Service1(from the basic WCF service) and this class is present in current NameSpace. So I changed class name as mynamespace.Service1
Some changes is code as shown below-
In web.config in Tag add following code
<system.web> <webServices> <conformanceWarnings> <remove name='BasicProfile1_1'/> </conformanceWarnings> </webServices> </system.web>
Add following 2 attribute on interface(on servicecontract of WCF)
[WebService(Name = "Service1")] [WebServiceBinding(Name = "Service1", ConformsTo = WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true)]
Add [WebMethod] attribute on each operation contract.
[OperationContract] [WebMethod] string GetData(int value);
your service can now be consumed by asmx client too.
来源:https://stackoverflow.com/questions/4718557/wcf-svc-service-but-client-wants-to-connect-as-if-it-was-asmx