Android クライアントから WCF サービスを呼び出そうとしていますが、End of input at character 0 of
エラーが発生しました。WCF Client Test でテストしたときはサービスが正常に動作していましたが、Android クライアントで試したときは機能せず、入力エラーの終了が生成されました...何が欠けているのかわかりません..
ここに私のコードがあります
EmployeeInfo.svc
namespace EmployeeServices
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "EmployeeInfo" in code, svc and config file together.
public class EmployeeInfo : IEmployeeInfo
{
public Employee GetEmployee(int employeeId)
{
Employee employeeInfo = GetEmployees(employeeId).Where(employee => employee.EmployeeId == employeeId).FirstOrDefault();
return employeeInfo;
}
private List<Employee> GetEmployees(int employeeId)
{
return new List<Employee> {
new Employee { EmployeeId = 11, FirstName = "Waqas", LastName = "Yousuf", Address="A-175 Block 1" , BloodGroup = "B+" },
new Employee { EmployeeId = 22, FirstName = "Moiz", LastName = "Ahmed", Address="B-176 Block 2" , BloodGroup = "O-" },
new Employee { EmployeeId = 33, FirstName = "Waqas", LastName = "Raza", Address="C-177 Block 3" , BloodGroup = "A+" },
new Employee { EmployeeId = 44, FirstName = "Yasir", LastName = "Amin", Address="D-178 Block 4" , BloodGroup = "AB+" },
new Employee { EmployeeId = 55, FirstName = "Adeel", LastName = "Ali", Address="E-179 Block 5" , BloodGroup = "B+" } };
}
}
}
IEmployeeInfo.cs
namespace EmployeeServices
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IEmployeeInfo" in both code and config file together.
[ServiceContract(Namespace = "http://services.example.com")]
public interface IEmployeeInfo
{
[OperationContract]
[WebGet(UriTemplate = "GetEmployee/{employeeId}",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
Employee GetEmployee(int employeeId);
}
[DataContract]
public class Employee
{
[DataMember]
public int EmployeeId { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public string BloodGroup { get; set; }
}
}
ここにweb.configがあります
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<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" />
<services>
<service name="EmployeeService.EmployeeInfo">
<endpoint kind="webHttpEndpoint"
contract="EmployeeService.IEmployeeInfo" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Android メソッド
try {
String SERVICE_URI = "http://192.168.1.4:1234/Employeeinfo.svc";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(SERVICE_URI + "/GetEmployee/11");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
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();
JSONObject Emp = new JSONObject(new String(buffer));
// Populate text fields
ed1.setText(Emp.getString("Address"));
ed2.setText(Emp.getString("BloodGroup"));
ed3.setText(Emp.getString("EmployeeId"));
ed4.setText(Emp.getString("FirstName"));
ed5.setText(Emp.getString("LastName"));
}
catch (Exception e) {
e.printStackTrace();
lblStatus.setText(e.getMessage());
}
AndroidアプリケーションからWCFサービスを呼び出す方法を学ぶために何日も働いていますが、ここに押し込んでいます...助けてください