2013-03-22 72 views
1

我想从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服务,我每天进食这里......请帮助

+0

我从安卓cliend调用它,我不知道,如果在客户端或其中u得到这个eror服务器 – 2013-03-22 04:12:38

+0

问题?这是客户的追赶吗?输入结束在字符0的 – 2013-03-22 04:31:15

+0

是来自客户 – 2013-03-22 04:33:58

回答

0

只是增加的大小该值显示在图像上的6553600。 enter image description here

WebGet(UriTemplate = "GetEmployee/{employeeId}", 
      BodyStyle = WebMessageBodyStyle.WrappedRequest, 
      ResponseFormat = WebMessageFormat.Json, 
Method="GET", 
      RequestFormat = WebMessageFormat.Json)] 
+0

也是在wcf的webget中添加Method =“GET”... – 2013-03-22 04:45:33

+0

什么也没有发生同样的错误 – 2013-03-22 04:55:53

+0

我应该在哪里添加Method =“GET” – 2013-03-22 05:04:04

相关问题