我想從Android客戶端調用WCF服務,我得到End of input at character 0 of
錯誤。服務工作正常,當我測試它與WCF客戶端測試,但是當我在Android客戶端嘗試它,它沒有和輸入錯誤生成結束...我不知道我失去了什麼......WCF:輸入結束在字符0
所以這裏是我的代碼
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服務,我每天進食這裏......請幫助
我從安卓cliend調用它,我不知道,如果在客戶端或其中u得到這個eror服務器 – 2013-03-22 04:12:38
問題?這是客戶的追趕嗎?輸入結束在字符0的 – 2013-03-22 04:31:15
是來自客戶 – 2013-03-22 04:33:58