WCF 및 Android를 처음 사용합니다. 그래서, 아마도 쉽게 질문 :
이 WCF 서비스 라이브러리입니다 죄송합니다 :android에서 WCF 메소드를 사용할 수 없습니다.
[ServiceBehavior]
public class CheckInService : ICheckInService
{
public string Hello()
{
return "Message from WCF!";
}
}
[ServiceContract]
public interface ICheckInService
{
[OperationContract]
[WebInvoke(
Method = "POST",
UriTemplate = "Hello",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
string Hello();
}
이 WCF 서비스 웹 사이트에서이 WCF 서비스에서의 app.config됩니다 Service.svc
<%@ ServiceHost Language="C#" Debug="true" Service="TYT.Service.CheckInService" %>
입니다 라이브러리 프로젝트 :
: 이것은 WCF 서비스 웹 사이트에서 웹 설정이<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="TYT.Service.CheckInService">
<endpoint address="publicService" binding="basicHttpBinding" contract="TYT.Service.ICheckInService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/TYT.Service/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
입니다 691,363,210
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="TYT.Service.CheckInService">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="TYT.Service.ICheckInService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
인조 CODE
private final static String SERVICE_URI = "http://10.0.2.2/tytservice/Service.svc";
try {
// Send GET request to <service>/GetPlates
HttpGet request = new HttpGet(SERVICE_URI + "/Hello");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
String data = new String(buffer);
그러나 데이터 문자열에서 내가 얻을 모두 다음과 같은 오류로 전체 HTML 문서입니다 : 내가 http://localhost/tytservice/Service.svc
에 브라우저에서 이동하면 내가 서비스 설명을 볼 수
<span><H1>Server Error in '/tytservice' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The resource cannot be found.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
<br><br>
<b> Requested URL: </b>/tytservice/Service.svc/Hello<br><br>
...
</html>
<!--
[EndpointNotFoundException]: There was no channel actively listening at 'http://vlada-nb/tytservice/Service.svc/Hello'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
[HttpException]: There was no channel actively listening at 'http://vlada-nb/tytservice/Service.svc/Hello'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)
-->
은 하지만 http://localhost/tytservice/Service.svc/Hello
을 추가하면 404가 다시 나타납니다.
이 방법은 노출되지 않지만 여기에서 내가 놓친 것을 이해할 수는 없습니다.