【问题标题】:DefaultProxy works when I use this on WinForms Application but won't works in WCF?当我在 WinForms 应用程序上使用 DefaultProxy 时有效,但在 WCF 中无效?
【发布时间】:2020-03-09 08:34:14
【问题描述】:

首先,对于任何错误,我们深表歉意。英语不是我的母语

当我设置时,我有一个与 SOAP WS 通信的应用程序 <defaultProxy enabled="true" useDefaultCredentials="true">在 WinForm 应用程序的 app.config 上,请求响应是正确的,但如果我把它放在 WCF Windows 服务的同一部分,我会得到响应:没有端点监听。

    <binding name="BasicHttpBinding_IGDServices" receiveTimeout="00:10:00"
      sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647" textEncoding="utf-8" useDefaultWebProxy="true"
      messageEncoding="Mtom" />
    <binding name="mywsname" receiveTimeout="00:10:00"
      sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647" useDefaultWebProxy="true">
      <readerQuotas maxStringContentLength="2147483647" />
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="mywsendpoint"
      binding="mywsbinding" bindingConfiguration="mywsbinding"
      contract="mywscontract" name="mywsname" />

我尝试设置代理,但得到响应:输入字符串格式不正确

<defaultProxy enabled="true" useDefaultCredentials="true">
  <proxy proxyaddress="myproxyadressandport"/>
</defaultProxy>

两个应用程序的所有参数或方法都以相同的方式实现。

有人可以帮我吗?

【问题讨论】:

    标签: c# wcf soap service proxy


    【解决方案1】:

    你的英语很好。代理设置是绑定配置的一部分。我们通常在绑定属性中设置代理地址。

    <system.serviceModel>
            <bindings>
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IService"  proxyAddress="myproxyaddress"/>
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://10.157.13.70:8300/" binding="wsHttpBinding"
                    bindingConfiguration="WSHttpBinding_IService" contract="ServiceReference1.IService"
                    name="WSHttpBinding_IService">
                    <identity>
                        <userPrincipalName value="VABQIA593VM\Administrator" />
                    </identity>
                </endpoint>
            </client>
    </system.serviceModel>
    

    或者,

    WSHttpBinding binding = new WSHttpBinding();
                binding.BypassProxyOnLocal = false;
                binding.UseDefaultWebProxy = false;
                binding.ProxyAddress = new Uri("http://abcd");
    

    请参考以下官方文档。
    https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpbinding.proxyaddress?redirectedfrom=MSDN&view=netframework-4.0#System_ServiceModel_BasicHttpBinding_ProxyAddress
    https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/basichttpbinding?redirectedfrom=MSDN
    如果有什么可以帮助的,请随时告诉我。

    【讨论】:

    • 嗨,亚伯拉罕,感谢您的回答。我试过这样做,但即使这样,我仍然收到代理消息“没有端点监听”,而且,当我在我的 WinForms 应用程序上执行此操作时,它工作正常,仅在我的 WCF 中不起作用
    • 你的意思是它在 WinForms 应用程序中有效,在你的 WCF 中无效?你的 WCF 项目是什么?这两个项目应该是一种Client-side项目,通过添加服务引用来调用WCF服务。换句话说,自动生成的配置应该在 WinForms 应用程序和 WCF 应用程序之间是相同的。最后,请注意我们是否在客户端端点上使用bindingconfiguration属性应用了绑定配置。
    • 我希望您分享位于客户端的完整配置。即 Winform 和 WCF 中的 System.servicemodel 部分。
    猜你喜欢
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    相关资源
    最近更新 更多