我正在尝试在 Android 中使用我的以下 WCF Web 服务
这是我的代码
服务
登录服务
[ServiceContract]
public interface ILoginService
{
[OperationContract]
bool LoginUser(string uname, string password);
}
登录服务.svc.cs
public class LoginService : ILoginService
{
public bool LoginUser(string uname, string password)
{
if (uname == password)
return true;
else
return false;
}
}
和web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="LoginService.LoginService">
<endpoint binding="basicHttpBinding" contract="LoginService.ILoginService" ></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="LoginService.svc" />
</files>
</defaultDocument>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
<handlers>
<add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="File" preCondition="classicMode,runtimeVersionv4.0,bitness32"/>
<add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler" resourceType="File" preCondition="integratedMode"/>
</handlers>
</system.webServer>
</configuration>
我在 IIS 上托管了这项服务,并且在 dotnet 应用程序中运行良好。我用于访问此服务的 android 代码是
private void callServiceMethod() throws IOException, XmlPullParserException
{
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "LoginUser";
String SOAP_ACTION = "http://tempuri.org/LoginUser";
String URL = "http://192.168.16.61/LoginService/LoginService.svc";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("uname");
pi.setValue("jayant");
pi.setType(String.class);
Request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("password");
pi2.setValue("jayant");
pi2.setType(String.class);
Request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Result = Boolean.parseBoolean(response.getProperty(0).toString()) ;
}
运行此代码时,我的程序出现异常:XmlpullParserException : End tag expected
请告诉我我在哪里做错了?谢谢