2011-09-17 19 views
2

私はエンドポイントにエラーが見つかりませんでしたが、私にはWCFサービスがあります。Android PhoneのRESTサービスでエンドポイントが見つかりません

まず、インタフェース:

public interface ISightingServiceRest 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST", 
    UriTemplate = "SaveNewSightingRest", 
    ResponseFormat = WebMessageFormat.Json, 
    RequestFormat = WebMessageFormat.Json)] 
    string SaveNewSightingRest(string sighting); 
} 

さて、実際の方法:

public string SaveNewSightingRest(string sighting) 
{ 
    string received = sighting; 
    return "hola"; 
} 

私がデバッグだように、私が望むすべてが私の応答で "はいはい" の文字列を確認することです、送信された文字列を変数 "received"に格納します。今

、WebConfigの:

<?xml version="1.0"?> 
<configuration> 
    <connectionStrings> 
    <add name="LiveAndesWCF" connectionString="Data Source=BRUNO-PC\LIVEANDES; 
Initial Catalog=liveandes;Trusted_Connection=Yes;" 
providerName="System.Data.SqlClient"/> 
    <add name="LiveAndes" connectionString="Data Source=BRUNO-PC\LIVEANDES; Initial 
Catalog=liveandes;Trusted_Connection=Yes;" providerName="System.Data.SqlClient"/> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    <membership> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlMembershipProvider" 
      type="System.Web.Security.SqlMembershipProvider" 
      connectionStringName="LiveAndes" 
      enablePasswordRetrieval="false" enablePasswordReset="true" 
      requiresQuestionAndAnswer="false" requiresUniqueEmail="true"  
      maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" 
      minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" 
      applicationName="/"/> 
     </providers> 
    </membership> 
    </system.web> 
    <appSettings> 
    <!--Local--> 
    <add key="mainPathDeployWCF" value="http://localhost:61642/"/> 
    <add key="mainMachPathDeployWCF" value="\LiveAndesWCF\bin"/> 

    </appSettings> 

    <system.serviceModel> 
    <protocolMapping> 
     <add scheme="http" binding="wsHttpBinding" /> 
    </protocolMapping> 
    <services> 

     <service name="LiveAndesWCF.SightingServiceRest" 
      behaviorConfiguration="MetadataBehavior"> 
     <endpoint address="" behaviorConfiguration="WebBehavior" 
       binding="webHttpBinding" 
       contract="LiveAndesWCF.ISightingServiceRest"/> 
     </service> 

    </services> 
    <bindings> 
     <webHttpBinding> 
     <binding maxReceivedMessageSize="99999999" closeTimeout="00:02:00" 
      openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"> 
      <readerQuotas maxArrayLength="76384000" maxStringContentLength="2147483647"/> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="jsonBehavior"> 
      <enableWebScript/> 
     </behavior> 
     <behavior name="WebBehavior"> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior> 

      <serviceMetadata httpGetEnabled="true"/> 

      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     <behavior name="MetadataBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpGetUrl="" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

最後に、私はエミュレータから使っている方法:

private void addNewSighting() throws Exception 
{ 
    String URL = "http://10.0.2.2:61642/SightingServiceRest.svc"; 

    AlertDialog popup; 

    SightingWrapper sighting = new SightingWrapper(); 

    String xml = createXML(sighting); 

    try{ 
     HttpPost request = new HttpPost(URL + "/SaveNewSightingRest/"); 

     StringEntity sen = new StringEntity(xml); 

     request.setHeader("Accept", "application/json"); 
     request.setHeader("Content-type", "application/json; charset=utf-8"); 

     request.setEntity(sen); 

     DefaultHttpClient httpclient = new DefaultHttpClient(); 
     HttpResponse response = httpclient.execute(request); 

     HttpEntity responseEntity = response.getEntity(); 

     char[] buffer = new char[(int)responseEntity.getContentLength()]; 

     InputStream stream = responseEntity.getContent(); 
     InputStreamReader reader = new InputStreamReader(stream); 
     reader.read(buffer); 
     stream.close(); 

     String responseString = new String(buffer); 

    } 
    catch(Exception e) 
    {   

    } 

} 

私は "responseString" で受け取る "エンドポイントが見つかりません" というメッセージが表示されます。

私の誤りはどこにあるのか分かりません。

何か助けていただければ幸いです。

答えて

0

アドレス

HttpPost request = new HttpPost(URL + "/SaveNewSightingRest/"); //before 
HttpPost request = new HttpPost(URL + "/SaveNewSightingRest"); //after 
での最後のスラッシュを削除してくださいありがとう