简体   繁体   English

asp.net core 2.0 wcf 配置绑定

[英]asp.net core 2.0 wcf configure binding

I use a asp.net core 2.0 web api with a connected wcf service.我使用带有连接的 wcf 服务的 asp.net core 2.0 web api。 On normal asp.net i can configure the basicHttpBinding in the web.config .在普通的 asp.net 上,我可以在web.config配置basicHttpBinding But i can't find any solution to configurate the basicHttpBinding in asp.net core.但是我找不到任何解决方案来配置 asp.net core 中的basicHttpBinding

I have to set the transferMode="Streamed" and maxReceivedMessageSize="128108864" .我必须设置transferMode="Streamed"maxReceivedMessageSize="128108864"

Edit: it is a asp.net core 2.0 web api but with a full .net target framework编辑:它是一个 asp.net core 2.0 web api,但具有完整的 .net 目标框架

I have just encountered similar problems.我刚刚遇到了类似的问题。 So it seems that web.config is no longer available, because it's only used in IIS, and since Asp.net core 2 doesn't need IIS, web.config is irrelevant.所以看起来 web.config 不再可用,因为它只在 IIS 中使用,并且由于 Asp.net core 2 不需要 IIS,所以 web.config 无关紧要。 I did try to add it though, but it wouldn't work.我确实尝试添加它,但它不起作用。

Best thing is to do it programmatically.最好的办法是以编程方式进行。

BasicHttpBinding vidiBinding = new BasicHttpBinding();
vidiBinding.MaxReceivedMessageSize = 2000000;

EndpointAddress myEndPPtAdd = new EndpointAddress("http://localhost:9200/SilverlightVidiCloudService");

VidiExternalCloudServiceClient myClient = new VidiExternalCloudServiceClient(vidiBinding, myEndPPtAdd);
await myClient.OpenAsync();

You can add to your .net core project an App.config and add configurations for wcf service. 您可以将App.config添加到.net核心项目中,并添加wcf服务的配置。 In my case i added wcf service reference in class library project and copied auto generated wcf configuration from class library project to .net core project`s App.config. 以我为例,我在类库项目中添加了wcf服务参考,并将自动生成的wcf配置从类库项目复制到了.net核心项目的App.config中。

   <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IMyService">
          <security mode="None" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:3171/MyService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"
        contract="MyService.IMyService" name="WSHttpBinding_IMyService">
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM