WCF (svc) Service but client wants to connect as if it was “.asmx”

让人想犯罪 __ 提交于 2019-12-29 09:41:09

问题


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.

  1. Add new web service file (.asmx)
  2. Now open the node of web .asmx file and delete .asmx.cs file
  3. Once .cs file is deleted. You will find wcfasasmx.asmx file.
  4. 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

  5. Some changes is code as shown below-

  6. In web.config in Tag add following code

      <system.web>
       <webServices>
         <conformanceWarnings>
           <remove name='BasicProfile1_1'/>
         </conformanceWarnings>
       </webServices>
      </system.web>
    
  7. Add following 2 attribute on interface(on servicecontract of WCF)

     [WebService(Name = "Service1")]
     [WebServiceBinding(Name = "Service1", ConformsTo =   WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true)]
    
  8. 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

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