How to host a wcf application in iis and access it from Android device to get a json? I need to host a wcf application in iis and access it through the android device, how can this be done?
问问题
406 次
1 回答
1
这有很多教程..我正在为你列出一个教程列表..
1) http://romenlaw.blogspot.in/2008/08/sumption-web-services-from-android.html
2) http://www.kevingao.net/wcf-java-interop
来自一些stackoverflow答案的一些代码片段
[ServiceContract(Namespace="http://mycompany.com/LoginService")]
public interface ILoginService
{
[OperationContract]
string Login(string username, string password);
}
The implementation of the service could look like this:
public class LoginService : ILoginService
{
public string Login(string username, string password)
{
// Do something with username, password to get/create sessionId
string sessionId = "12345678";
return sessionId;
}
}
You can host this as a windows service using a ServiceHost, or you can host it in IIS like a normal ASP.NET web (service) application. There are a lot of tutorials out there for both of these.
The WCF service config might look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="LoginServiceBehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfTest.LoginService"
behaviorConfiguration="LoginServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress="http://somesite.com:55555/LoginService/" />
</baseAddresses>
</host>
<endpoint name="LoginService"
address=""
binding="basicHttpBinding"
contract="WcfTest.ILoginService" />
<endpoint name="LoginServiceMex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
在代码项目上也有很好的教程
http://www.codeproject.com/Articles/358867/WCF-and-Android-Part-I
如果您完成了 WCF 部分,那么上面的链接对您来说没有那么有用,下一部分将对您非常有用
http://www.codeproject.com/Articles/361107/WCF-and-Android-Part-II
于 2013-10-07T07:38:57.157 回答