首页 > 解决方案 > consume external WCF in netcore 2.0

问题描述

I have read something about it but I'm a little confused, so I would like to know if what I did its ok.

I created a WEBAPI in netcore 2.0 and I have to consume an external WCF (framework 4.5), I did a very simple test, for it I created a WCF and I could add the service referenece in the WEBAPI and I consumed it. So this example works fine

public async Task<WCFMySevrice.CompositeType> IndexTest2(WCFMySevrice.CompositeType value)
        {
            //Creating Client object of Service Reference
            WCFMySevrice.MyServiceClient client = new WCFMySevrice.MyServiceClient();
            //Call the method from WCF Service
            WCFMySevrice.CompositeType result = await client.GetDataUsingDataContractAsync(value);
            return result;
        }

My problem is that for now the url of my WCF is "http://localhost:55203/MyService.svc", but if I want to deploy my app in production environment the URL will change, is there a way to configure the endpoint? I have read about it, but I understand it is not possible and I need to create a proxy class with "WCF svcutil tool overview", but it is not clear for me. If i use it, don't I need anymore the service reference?

Any suggestion will be helpful.

标签: wcfasp.net-core-2.0

解决方案


When you published the wcf Service in visual studio, the service metadata address consisted of two parts. IIS would provide the following form.

http://10.157.13.69:8001

and the rest part of the address is consisted of the configuration. “/Data”</p>

<system.serviceModel>
    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="mybehavior">
        <endpoint address="Data" binding="wsHttpBinding" contract="WcfService1.IService1" bindingConfiguration="http"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>

the service address above is

http://10.157.13.69:8001/service1.svc/Data

and then we generate the client proxy class via Microsoft WCF web service reference provider.
That is, we can specify the service endpoint address through the configuration file.
Feel free to let me know if there is anything I can help with.


推荐阅读