2
我試着從Android使用WCF,我的代碼於Android,壞請求錯誤
private final static String SERVICE_URI = "http://188.59.2.211:8081/Survey.svc";
String email = "[email protected]";
String password = "123";
public void onResume() {
super.onResume();
Login(email,password);
}
private void Login(String email, String password)
{
try {
URL url = new URL(SERVICE_URI + "/Login/email="+email+"&password="+password);
HttpGet request = new HttpGet(url.toURI());
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpClient.execute(request);
if (response != null)
{
Log.i("login", "received " + response.toString());
}
else
{
Log.i("login", "got a null response");
}
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();
} catch (Exception e) {
e.printStackTrace();
}
}
和WCF服務端消費WCF,
[ServiceContract(Namespace = "http://saas.com")]
public interface ISurvey
{
[OperationContract]
[WebGet(
UriTemplate = "/Login/email={email}&password={password}",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
LoginResult Login(string email, string password);
}
和我的配置,
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="SAASService.Survey">
<endpoint address=""
behaviorConfiguration="httpBehavior"
binding="webHttpBinding"
contract="SAASService.ISurvey" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
問題的是,進出口使用下面的URL,
「http://188.59.2.211:8081/Survey.svc/Login/[email protected] &密碼= 123」
,它始終是給出「錯誤的請求」錯誤,statusCode = 400
出了什麼問題?