【问题标题】:how Consume IIS hosted WCF on a remote android device如何在远程 android 设备上使用 IIS 托管 WCF
【发布时间】:2013-09-04 07:12:08
【问题描述】:

我有一个托管在 IIS 上的 HTTP wcf。我使用android模拟器检查了本地机器上的服务。本地机器上的模拟器和 wcf 工作正常。

在网络浏览器中,我可以使用此 URL 访问服务:

 http://localhost:4806/Service1.svc

在 android 模拟器中,我使用 http://10.0.2.2:4806/Service1.svc 成功将 android 与 wcf 连接。

现在我想使用 android 设备访问 PC 上的 wcf。我怎样才能做到这一点?我需要对 web.config 文件进行任何更改吗? 是web.config文件代码

<service name="JSONService.Service1" behaviorConfiguration="JSONService.Service1Behavior">
  <!-- Service Endpoints -->
  <!--Change the binding to webHttpBinding and set behaviour configuratiion to web-->
  <endpoint address="" binding="webHttpBinding" contract="JSONService.IService1" behaviorConfiguration="web" >
    <!-- 
      Upon deployment, the following identity element should be removed or replaced to reflect the 
      identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
      automatically.
  -->

    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange"/>

</service>

</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="JSONService.Service1Behavior">
            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata httpGetEnabled="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>
    <!--Newly added configuration-->
    <endpointBehaviors>
        <behavior name="web">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
    <!--End of newly added Configuration-->
</behaviors>

感谢您的帮助。

已编辑:

我尝试使用像 http://192.168.1.67:4806/Service1.svc 这样的 PC 的 IP,并在 windowsfirewall 4806 中打开一个端口。我想从 android 设备登录并从 PC 上运行的 wcf 获得身份验证。现在,当我按下登录按钮时,应用程序会停止并给出错误止赎。任何帮助在这方面都会很棒。谢谢

【问题讨论】:

  • 您的 Android 设备是否属于同一网络?还是使用互联网?
  • @nvoigt,我在 pc 上使用互联网 LAN,在 android 上使用 wifi。我的 wifi 连接到 LAN 路由器。我也可以在没有互联网的情况下使用它,如果可以,我该怎么做。感谢回复
  • 主机端 IP 为 192.168.1.67,wifi 上的 IP 为 192.168.1.2。我也尝试在 android 手机网络浏览器中运行服务,但 wcf 无法访问。

标签: c# android wcf iis


【解决方案1】:

一般而言,您不需要对 web.config 进行任何更改即可从 android 客户端访问服务。

如果您认为 basicHttpBinding 就足够了,我想这对您最有效。您可以使用普通的 HTTPPost 继续。

【讨论】:

  • 检查此链接。在那里你会得到更多的信息。 stackoverflow.com/questions/669764/…
  • 我也检查了没有端口192.168.1.67/Service1.svc,但无法登录。
  • 你能检查一下传递的请求吗?由于它是 Web 绑定,因此应该生成基于 REST 的普通请求。还要检查您的 WCF 服务是否确实收到了它。尝试调试。
  • 我在 android 设备上使用 wifi,而 PC 使用 LAN 互联网连接。 wcf 处于调试模式,但如何检查 wcf 是否接收到它?
  • 我必须在真机上使用,否则它在安卓模拟器上工作正常,但由于模拟器不支持蓝牙,我必须在真机上测试它。我在virtualbox中尝试了模拟器来启用蓝牙。它已启用,但由于我的电脑没有内置蓝牙,我正在使用蓝牙加密狗。但是对于单个加密狗,我无法将在虚拟框中运行的 android 模拟器与在 HOst xp 上的同一台 PC 上运行的 wcf 连接。您知道通过单个加密狗将主机 xp 与 android x86 VM 连接的任何方法吗?如果可能的话,它可以解决我的问题。
猜你喜欢
  • 1970-01-01
  • 2016-06-06
  • 1970-01-01
  • 2013-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-25
  • 1970-01-01
相关资源
最近更新 更多