Я так новичок в обслуживании android и wcf. У меня есть искупление.Служба WCF для Android
Это андроид функции:
private void Post(String VAL)
{
HttpClient httpClient = new DefaultHttpClient();
try
{
String aaa = "aaa";
String url = "http://192.168.30.117:59151/IService1";
HttpPost method = new HttpPost(url);
StringEntity e = new StringEntity("{ \"something\":12345 }", "UTF-8");
method.setEntity(e);
method.setHeader("content-type", "application/json");
method.setHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(method);
HttpEntity entity = response.getEntity();
if(entity != null)
{
System.out.println(entity);
}
} catch (IOException e) {
Log.e("error", e.getMessage());
}}
здесь ФОС часть:
[ServiceContract()]
public interface IService1
{
[OperationContract]
[WebInvoke(Method= "POST", UriTemplate = "GetData?parameter={parameter}", ResponseFormat = WebMessageFormat.Json)]
string GetData(string parameter);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
public string GetData(String value)
{
return string.Format("You entered: {0}", value);
}
и это конфигурационный файл:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="http_behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="http_behavior" name="WcfServiceGps.Service1">
<endpoint address="" binding="webHttpBinding" bindingConfiguration=""
name="GetData" contract="WcfServiceGps.IService1" />
<endpoint address="mex" binding="mexHttpBinding" name="GetDataMex"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://192.168.30.117:59151/Service1.svc/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
, когда я называю обслуживание от android
HttpResponse response = httpClient.execute(method);
дает следующее исключение:
Возможно, вы заполните, пожалуйста, исключение, которое вы видите ниже последней строки. Спасибо. – Animesh
FATAL ИСКЛЮЧЕНИЯ: главный процесс: com.example.celal.gpssystem, PID: 4298 android.os.NetworkOnMainThreadException в android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork –