Ich bin so neu über Android und WCF-Service. Ich habe eine Erwartung.WCF Service Android Verbindung
Dies ist android Funktion:
[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);
}
und das ist config-Datei:
<?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>
wenn ich rufen werde die
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());
}}
hier
wcf Teil ist Service von Android
HttpResponse response = httpClient.execute(method);
es gibt die folgende Ausnahme:
Können Sie bitte die Ausnahme ausfüllen, die Sie erhalten, bitte unter der letzten Zeile? Vielen Dank. – Animesh
FATAL AUSNAHME: Haupt Prozess: com.example.celal.gpssystem, PID: 4298 android.os.NetworkOnMainThreadException bei android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork –