好的,我有一个WCF服务,让我发现一个Endpoint not found错误,我看不出它为什么...这是我的代码。
首先,界面:
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";
}
当我正在调试时,我想要的只是在我的响应中看到字符串“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”中收到“Endpoint not found”消息。
我不知道我的错误在哪里。
感谢任何帮助。
谢谢
答案 0 :(得分:0)
尝试删除地址
中的尾部斜杠HttpPost request = new HttpPost(URL + "/SaveNewSightingRest/"); //before
HttpPost request = new HttpPost(URL + "/SaveNewSightingRest"); //after