【发布时间】: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 无法访问。