我有一个 Wcf Web 服务和一个调用服务方法的 android 应用程序。要求进行某种身份验证,最好使用用户名/密码组合。数据不敏感,但我只需要使服务只能从 android 应用程序访问。任何帮助是极大的赞赏。
我有多种方法与此非常相似
<OperationContract()> _
<WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.WrappedResponse, UriTemplate:="endpoint?busUnit={busUnit}")> _
Function lstJobsSVC(busUnit As String) As List(Of JobsView)
然后我在服务中实现方法如下
Public Function lstJobsSVC(busUnit As String) As List(Of JobsView) Implements IService1.lstJobsSVC
Dim entities As New RemoteTimeEntities()
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"
Return entities.lstJobs(busUnit).ToList
End Function
然后在安卓
URL json = new URL("http://localhost/json/Service1.svc/"+ "functions endpoint";
HttpURLConnection jc = (HttpURLConnection) json.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
readLine = reader.readLine();
JSONObject jsonResponse = new JSONObject(readLine);
JSONArray jsonArray = jsonResponse.getJSONArray("get json array name");
现在所有这些代码都可以正常工作我只是不明白如何实现在两者之间工作的身份验证。