簡體   English   中英

如何通過位於不同域的代理將WPF應用程序連接到WCF服務?

[英]How to connect a WPF app to a WCF service when going through a proxy sitting on a different domain?

提前致謝!

我們在域A中的PC上有一個WPF應用程序.PC被設置為指向另一個域B的代理。

我們有一個ASP.NET WebForms站點,位於托管WCF服務的域B中的Web服務器上。 該網站是HTTP,而不是HTTPS

代理服務器設置為使用Windows身份驗證,我們希望使用30域上的特定用戶來允許WPF應用程序使用它。 我們無法為我們的生活正確設置。

WPF應用程序綁定配置:

    <system.net>
        <defaultProxy useDefaultCredentials="true" />
      </system.net>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_IService" closeTimeout="00:05:00" openTimeout="00:05:00" 
                     receiveTimeout="00:5:00" sendTimeout="00:05:00" allowCookies="false" 
                     bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" 
                     maxBufferPoolSize="65536" maxReceivedMessageSize="2147483647" messageEncoding="Text" 
                     textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false" proxyAddress="http://192.168.30.221">
              <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
      </system.serviceModel>

網站WCF配置:

<system.serviceModel>
    <services>
      <service name="QuickScripts.Website.ScriptService" behaviorConfiguration="newbehaviour">
        <endpoint name="default" address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService" contract="QuickScripts.Service.IService" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="newbehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

我們希望盡可能多地配置這個,盡管我認為這是不言而喻的。

我們使用ChannelFactory在代碼中創建客戶端:

var factory = new ChannelFactory<IService>(_binding, new EndpointAddress(_url));

_instance = factory.CreateChannel();

我們還嘗試通過Credentials.UserName.UserName / Password將憑證應用於工廠,但再一次無濟於事。

所以我想主要的兩個問題是,這是否可能(當然可以)? 有誰知道我們哪里出錯了?

幾年前我不得不這樣做。

我所做的是在IIS中添加一個新的端口重定向並使用我選擇的隨機端口(我認為我使用的是端口82)。 然后我使用該端口連接到我的WCF而不是http://MyServer/MyService我正在使用http://MyServer:82/MyService

執行此操作后,域管理員將端口82限制為僅允許使用該應用程序的人員非常簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM