Is possible to access WCF Service without adding Service Reference?

后端 未结 5 1692
太阳男子
太阳男子 2020-12-13 14:38

I need to access Wcf service methods without adding Service Reference?how to do this?

Step 1:I create a WCF Service.
Step 2:Add Service Reference to my applicati

5条回答
  •  [愿得一人]
    2020-12-13 15:40

    Yes, it is possible to invoke as WCF service without adding a service reference.

    As a first step, I assume that you have your service contact interface as a separate class library.

    Step 2: Create your WCF service and host it in IIS

    Step 3: Refer your service contract library in the client application and then follow this code

    ChannelFactory factory = new ChannelFactory("EndpointNameOfYourService");
    factory.Endpoint.Address = new EndpointAddress("http://example.com/service");  
    
    IYourServiceContract client = factory.CreateChannel();
    var result = client.YourMethodtoInvoke(serviceArguments);
    

    Hope this helps

提交回复
热议问题