如何从托管在另一台服务器上的 Web 应用程序调用托管在客户端机器上的 WcfService?

问题描述

我有一个 WcfService 托管在用户(客户端)计算机上的控制台应用程序上,该服务提供对文档扫描仪设备 (Avision AD240) 的访问以扫描文档,并希望从其他网站(例如托管在 www.someotherdomain.com 上)调用此服务. 总结:我的网站用户使用 jetScan 文档扫描仪,并希望将扫描的图像上传到网站的服务器上。我已在本地 IIS 中完成此操作,但我不知道如何在远程服务器托管的 Web 应用程序中处理本地托管服务。

我的 WcfService Web.Config 文件如下所示:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IScannerService" maxReceivedMessageSize="2147483647">
 
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information,set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes,set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="WcfServiceScanner.ScannerService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScannerService" contract="WcfServiceScanner.IScannerService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfServiceScanner/WcfServiceScanner/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <protocolMapping>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <!--<modules runAllManagedModulesForAllRequests="true"/>-->
    <!--
        To browse web app root directory during debugging,set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Headers" value="Content-Type,Accept" />
        <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
        <add name="Access-Control-Max-Age" value="1728000" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

</configuration>

我的远程服务器 Web 应用程序 web.config 文件的一部分如下所示:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IScannerService"  maxReceivedMessageSize="2147483647"/>
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_IScannerService">
          <security>
            <transport sslProtocols="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8080/WcfService" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IScannerService" contract="WcfScannerService.IScannerService"
        name="BasicHttpBinding_IScannerService" />
      <endpoint address="net.tcp://localhost:8090/WcfService" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_IScannerService" contract="WcfScannerService.IScannerService"
        name="NetTcpBinding_IScannerService">
        <identity>
          <userPrincipalName value="DESKTOP-KILE609\Hosein" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

解决方法

如果代码可在本地访问,则该代码很好。 以下步骤可能对您有所帮助:

  1. 确保网络在另一台机器上正常工作。
  2. 检查IP地址和端口是否被防火墙占用或屏蔽。
  3. 在 url 的末尾添加 ?wsdl,如果可行并向您显示 xml 文件,则该服务是可以访问的。

谢谢。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...