在android上使用WCF服务-主机名无效
我需要在我的android应用程序中调用WCF服务。对于通信,我使用OkHttp库。在桌面浏览器中,服务在url上运行良好,如下所示:在android上使用WCF服务-主机名无效,android,rest,wcf,http,Android,Rest,Wcf,Http,我需要在我的android应用程序中调用WCF服务。对于通信,我使用OkHttp库。在桌面浏览器中,服务在url上运行良好,如下所示: http://localhost:7915/GeoService.svc/GetRoute?source=kyjevska&target=cyrila 以下是WCF合同: [ServiceContract] public interface IGeoService { [OperationContract] [WebInvoke(Met
http://localhost:7915/GeoService.svc/GetRoute?source=kyjevska&target=cyrila
以下是WCF合同:
[ServiceContract]
public interface IGeoService
{
[OperationContract]
[WebInvoke(Method ="GET", UriTemplate = "/GetRoute?source={source_addr}&target={target_addr}",
BodyStyle = WebMessageBodyStyle.Bare)]
Stream GetRoute(string source_addr, string target_addr);
}
服务代码:
public Stream GetRoute(string source_addr, string target_addr)
{
...
...
byte[] resultBytes = Encoding.UTF8.GetBytes(result);
WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
return new MemoryStream(resultBytes);
}
和web.config:
在我的解决方案目录中,我找到了applicationhost.config,其中绑定了我的WCF站点:
<sites>
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
</bindings>
</site>
<site name="GeocodeWCF" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\Bachelor\GeocodeAPI\GeocodeWCF" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:7915:localhost" />
</bindings>
</site>
<site name="WcfService1" id="3">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\Bachelor\GeocodeAPI\WcfService1" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8745:localhost" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
您能帮我修复它吗?我使用commande ipconfig/all并查找LAN适配器的ipv4地址: 像这样的url工作:
http://192.168.182.1:7915/SomeService.svc/SomeFunction?source=xxx&target=xxx
如果仍然不起作用,请尝试在IIS管理器applicationhost.config中设置绑定,并为该端口添加防火墙规则
http://192.168.182.1:7915/SomeService.svc/SomeFunction?source=xxx&target=xxx