托管一个wcf应用程序并从Android设备访问它,该怎么做?

时间:2013-10-07 07:32:08

标签: android

如何在iis中托管wcf应用程序并从Android设备访问它以获取json?我需要在iis中托管一个wcf应用程序并通过android设备访问它,如何做到这一点?

1 个答案:

答案 0 :(得分:1)

有很多这方面的教程..我正在为你准备一份教程列表..

1)http://romenlaw.blogspot.in/2008/08/consuming-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> 

礼貌:How to Consume WCF Service with Android

同样在代码项目上有很好的教程

http://www.codeproject.com/Articles/358867/WCF-and-Android-Part-I

如果你完成了WCF部分,那么上面的链接对你没那么有用,下一部分对于

非常有用

http://www.codeproject.com/Articles/361107/WCF-and-Android-Part-II