【问题标题】:How to access WCF service from Remote Desktop to another machine in c# application?如何在 C# 应用程序中从远程桌面访问 WCF 服务到另一台机器?
【发布时间】:2020-04-27 08:31:33
【问题描述】:

我已经在远程桌面机器的 IIS 上部署了 WCF 服务。我可以在本地计算机的 chrome 浏览器中访问该服务,并且已将其作为服务引用添加到我的项目中。现在,当我的项目尝试访问服务时,它给了我类似 The caller was not authenticated by the service. 的错误。

在与它相关的研发之后,我在下面添加了解决方案

_client.ClientCredentials.Windows.ClientCredential.Domain = "RDP Computer name";
_client.ClientCredentials.Windows.ClientCredential.UserName = "RDP Username";
_client.ClientCredentials.Windows.ClientCredential.Password = "RDP Password";

当我再次尝试时,错误更改为 Client is unable to finish the security negotiation within the configured timeout (00:00:00). The current negotiation leg is 1 (00:00:00).

我尝试根据https://support.microsoft.com/en-in/help/17463/windows-7-connect-to-another-computer-remote-desktop-connection 的建议在 RDP 机器上查找域名。但是我在那里没有找到任何域名。它是工作组区域中可用的工作组名称。

在我的本地机器项目 app.config 文件中包含如下服务代码:

<system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IService1">
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://xx.xx.xxx.xxx/Testing/Service1.svc"
        binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="WSDualHttpBinding_IService1">
        <identity>
          <servicePrincipalName value="host/RDPName" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

但是在 WCF 服务项目端 web.config 文件包含以下代码:

<protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

    <services>
      <service name="WcfService.Service1">
        <endpoint address="" binding="wsDualHttpBinding" contract="WcfService.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <timeouts closeTimeout="00:05:00" openTimeout="00:05:00" />
        </host>
      </service>
    </services>
    <bindings>
      <wsDualHttpBinding>
        <binding name="customBinding0"
                receiveTimeout="00:05:00"
                sendTimeout="00:05:00"
                openTimeout="00:05:00"
                closeTimeout="00:05:00"
                maxBufferPoolSize="2147483647"
                maxReceivedMessageSize="2147483647">
          <security mode="None">
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>

我最近几天正在做研发以解决这个问题,但根本没有成功。

请你建议我应该怎么做才能解决这个问题?

谢谢。

【问题讨论】:

  • 您可能能够通过 RDP 连接到远程计算机,因为 RDP 端口在防火墙处已打开,但您可能无法访问任何其他端口,因为防火墙可以阻止它。同样对于工作组设置,用户帐户不能跨越不同的机器。您最好通过 AD 设置域。
  • @LexLi。我尝试通过允许该端口接收传入请求来设置入站规则。但它在这种情况下不起作用。但是让我尝试设置新域名。
  • 请创建一个活动目录域。这样您的服务器就能够验证 kerberos 或 NTLM 令牌。此外,您必须确保 80 端口已暴露在互联网上。我的意思是服务器门户中的服务器内部防火墙和外部防火墙墙。
  • “我尝试通过允许该端口设置入站规则”,您为 WCF 打开了哪个端口?说清楚。

标签: c# wcf iis wcf-data-services


【解决方案1】:

在我这边,设置 Windows 凭据后它可以正常工作。这是因为 wsdualhttpbinding 创建的 WCF 默认使用 Windows 凭据对客户端进行身份验证。
另外,为什么服务地址有“Testing”前缀?并且服务地址是无效的。你在用virtual path吗?
事实上,没有必要使用双面绑定。 wshttpbinding就够了,还是nettcpbinding,同样支持双工通信。 Wsdualhttpbinding 可能会被防火墙阻止,因为它支持回调协定。
请参考以下讨论。
WCF Duplex - Client is unable to finish the security negotiation within the configured timeout
https://social.msdn.microsoft.com/Forums/en-US/21160b92-bed5-4e5d-a1a9-6fc8e84f6299/client-is-unable-to-finish-the-security-negotiation-within-the-configured-timeout-000000-the?forum=csf
https://help.octopus.com/t/client-is-unable-to-finish-the-security-negotiation-within-the-configured-timeout/6827
如果有什么可以帮助的,请随时告诉我。
已更新。
为了排除身份验证和网络问题,我建议您先使用 Basichttpbinding 创建 WCF 服务。客户端可以通过adding service reference 使用服务。请参考配置。
服务器端。

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

期待您的进一步消息。

【讨论】:

  • 感谢您的回复。我尝试了您提供的链接,但我的应用程序仍然无法访问我在 RDP IIS 服务器上部署的服务。请问你能指导我这个吗?
猜你喜欢
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多