Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable programmable WCF proxy settings. #280

Open
daisukenishino2 opened this issue Mar 13, 2018 · 0 comments
Open

Enable programmable WCF proxy settings. #280

daisukenishino2 opened this issue Mar 13, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@daisukenishino2
Copy link
Member

daisukenishino2 commented Mar 13, 2018

Requirement

I tested the proxy settings of the communication control function due to the another matter.
As a result of the following settings, proxy setting in XML was possible except for WCF.
This result was verified using fiddler http debug proxy (127.0.0.1:8888).

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE TMD[
  <!ELEMENT TMD (Prop*, Url*, Transmission*)>

  <!ELEMENT Url EMPTY>
  <!ELEMENT Prop EMPTY>
  <!ELEMENT Transmission EMPTY>

  <!ATTLIST Url id ID #REQUIRED value CDATA #REQUIRED>
  <!ATTLIST Prop id ID #REQUIRED value CDATA #REQUIRED>
  <!ATTLIST Transmission id ID #REQUIRED protocol (1 | 2) #REQUIRED 
    url CDATA #IMPLIED url_ref IDREF #IMPLIED timeout CDATA #IMPLIED prop_ref IDREF #IMPLIED>
]>
<!-- idの先頭には、数字を使用できない。 -->
<!-- protocol:1=InProcess、2=WebService -->
<TMD>
  <!-- マスタ データ -->

  <!-- 接続URL(asmx単位に定義する) -->
  <Url id="url_a" value="http://xxx.xxx.xxx.xxx/ASPNETWebService/ServiceForFx.asmx"/>
  <Url id="url_b" value="http://xxx.xxx.xxx.xxx/ASPNETWebService/WCFHTTPSvcForFx.svc"/>
  <Url id="url_c" value="net.tcp://localhost:7777/WCFService/WCFTCPSvcForFx/"/>
  <Url id="url_d" value="http://xxx.xxx.xxx.xxx/ASPNETWebService/DotNETOnlineWebAPI"/>

  <!-- 接続オプション(必要に応じて) -->
  <Prop id="prop_a" value="ProxyUrl=http://127.0.0.1:8888;"/>

  <!-- 接続先 データ -->

  <!-- インプロセス -->
  <Transmission id="testInProcess" protocol="1"/>

  <!-- サービス -->

  <!-- サービス(マスタ データを活用)-->
  <Transmission id="testWebService" protocol="2" url_ref="url_a" timeout="60" prop_ref="prop_a" />
  <Transmission id="testWebService2" protocol="3" url_ref="url_b" timeout="60" prop_ref="prop_a" />
  <Transmission id="testWebService3" protocol="4" url_ref="url_c" timeout="60" prop_ref="prop_a" />
  <Transmission id="testWebService4" protocol="5" url_ref="url_d" timeout="60" prop_ref="prop_a" />
</TMD>

In the current specification, this setting is done in the binding section for WCF.
However, I found the following information to which XML settings can be applied.

  BasicHttpBinding binding = (BasicHttpBinding)service.Endpoint.Binding;
    binding.BypassProxyOnLocal = true;
    binding.UseDefaultWebProxy = false;
    binding.ProxyAddress = new Uri(proxyServer);
 void SetProxySettings<TChannel>(ClientBase<TChannel> client, 
     bool useProxy, string address, int port, string login, string password) 
     where TChannel : class
 {
     if (!useProxy) return;
     var b = client.Endpoint.Binding as BasicHttpBinding;
     if (b == null)
     {
         System.Diagnostics.Debug.WriteLine("Binding of this endpoint is not BasicHttpBinding");
         return;
     }
     b.ProxyAddress = new Uri(string.Format("http://{0}:{1}", address, port));
     b.UseDefaultWebProxy = false; // !!!
     b.Security.Mode = BasicHttpSecurityMode.Transport;
     b.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; // !!!
     b.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic; // !!!
     if (client.ClientCredentials == null) return;
     client.ClientCredentials.UserName.UserName = login;
     client.ClientCredentials.UserName.Password = password;
 }
<basicHttpBinding>  
   <binding   
       allowCookies="Boolean"  
       bypassProxyOnLocal="Boolean"  
       closeTimeout="TimeSpan"   
       envelopeVersion="None/Soap11/Soap12"  
       hostNameComparisonMode="StrongWildCard/Exact/WeakWildcard"  
       maxBufferPoolSize="Integer"  
       maxBufferSize="Integer"  
       maxReceivedMessageSize="Integer"  
       messageEncoding="Text/Mtom"  
              name="string"   
       openTimeout="TimeSpan"   
       proxyAddress="URI"  
        receiveTimeout="TimeSpan"  
       sendTimeout="TimeSpan"  
              textEncoding="UnicodeFffeTextEncoding/Utf16TextEncoding/Utf8TextEncoding"  
              transferMode="Buffered/Streamed/StreamedRequest/StreamedResponse"  
       useDefaultWebProxy="Boolean"  
       <security mode="None/Transport/Message/TransportWithMessageCredential/TransportCredentialOnly">  
           <transport clientCredentialType="None/Basic/Digest/Ntlm/Windows/Certificate"  
                  proxyCredentialType="None/Basic/Digest/Ntlm/Windows"  
                                    realm="string" />
@daisukenishino2 daisukenishino2 added the enhancement New feature or request label Mar 13, 2018
@daisukenishino2 daisukenishino2 added this to the Release of 02-x0 version milestone Mar 13, 2018
@daisukenishino2 daisukenishino2 removed this from the Release of 02-30 version milestone Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant