Search code examples
c#wcfsoapserviceproxy

DefaultProxy works when I use this on WinForms Application but won't works in WCF?


first of all, sorry for any mistakes. English is not my native language

I've an application that's communicates with an SOAP WS, when I set <defaultProxy enabled="true" useDefaultCredentials="true">on the app.config of an WinForm Application, the request response is correct, but if I put this on the same section of an WCF Windows Service I've got the response: There was no endpoint listening.

    <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" />

I've tried to set the proxy, but got the response: Input string was not in a correct format

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

All the parameters or methods of both applications are implemented on the same way.

Can someone help me?


Solution

  • Your English is good. The proxy settings are part of the binding configuration. We usually set up the proxy address in the binding property.

    <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>
    

    Or,

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

    Please refer to the below official document.
    https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpbinding.proxyaddress?redirectedfrom=MSDN&view=netframework-4.0#System_ServiceModel_BasicHttpBinding_ProxyAddress
    https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/basichttpbinding?redirectedfrom=MSDN
    Feel free to let me know if there is anything I can help with.