wcf - 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.
解决方案
When you published the wcf Service in visual studio, the service metadata address consisted of two parts. IIS would provide the following form.
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
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.
推荐阅读
- python - 如何在 OpenShift 上运行 InstaBot.py?
- javascript - Javacsript - 使用 2 个变量键访问嵌套对象值(用于 ReactJS setState())
- java - 更改传递值java的值
- ios - AudioKit 4.3:录制音频,离线渲染,然后播放
- go - 如何使用 Golang 中的 goroutine 从标准输入读取?
- ruby-on-rails - Rails 部署 Digitalocean ActiveSupport::MessageEncryptor::InvalidMessage:
- python - 在python中查找字符串中的单词索引
- python - AWS S3 boto 下载错误
- c++ - AddressSanitizer:新删除类型与 mysql-connector-c++ 不匹配
- android - SQLite 创建表语法错误 [Android]