2013-01-09 83 views
0

我已经使用在服务器端的代码,如何在windows phone7应用程序中使用wcf服务?

[OperationContract]   
     [WebInvoke(Method = "POST", UriTemplate = "/UploadData?Name={Name}&Email={Email}&ContactNumber={ContactNumber}&DeviceModel={DeviceModel}&Problem={Problem}&Besttimetocontact={Besttimetocontact}",   
      BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)] 
     NewClsMessage UploadData(string Name, string Email, string ContactNumber, string DeviceModel, string Problem, string Besttimetocontact); 

public NewClsMessage UploadData(string Name, string Email, string ContactNumber, string DeviceModel, string Problem, string Besttimetocontact) 
{ 
      NewClsMessage ObjNewClsMessage = new NewClsMessage(); 
      try 
      { 
    str_value = "insert into Estimate(Name,Email,ContactNumber,DeviceModel,Problem,Besttimetocontact) values('" + Name + "','" + Email + "','" + ContactNumber + "','" + DeviceModel + "','" + Problem + "', '" + Besttimetocontact + "')";     

       OpenConnection(); 
       sqlCmd.CommandType = CommandType.Text; 
       sqlCmd.CommandText = str_value; 
       value = sqlCmd.ExecuteNonQuery(); 
       if (value > 0) 
       { 
        ObjNewClsMessage = new NewClsMessage(); 
        ObjNewClsMessage.Result = "1"; 
        ObjNewClsMessage.Message = "send Successfully"; 
       } 
       else 
       { 
        ObjNewClsMessage = new NewClsMessage(); 
        ObjNewClsMessage.Result = "0"; 
        ObjNewClsMessage.Message = "Free Estimate not send Successfully"; 
       } 
} 

catch (Exception ex) 
      { 
      } 
      return ObjNewClsMessage; 

客户端代码,

WebClient webClient = new WebClient(); 
      webClient.Headers[HttpRequestHeader.ContentType] = "application/xml"; 
      // var uri = new Uri("localhost:55666/WcfPostMethod/Service.svc/UploadXml"); 
      var uri = new Uri("http://localhost:50546/Service1.svc/UploadData"); 
      StringBuilder postData = new StringBuilder(); 
      postData.AppendFormat("?{0}={1}", "Name", HttpUtility.UrlEncode("hi")); 
      postData.AppendFormat("&{0}={1}", "Email", HttpUtility.UrlEncode("[email protected]")); 
      postData.AppendFormat("&{0}={1}", "ContactNumber", HttpUtility.UrlEncode("56898")); 
      postData.AppendFormat("&{0}={1}", "DeviceModel", HttpUtility.UrlEncode("E4376")); 
      postData.AppendFormat("&{0}={1}", "Problem", HttpUtility.UrlEncode("Repair")); 
      postData.AppendFormat("&{0}={1}", "Besttimetocontact", HttpUtility.UrlEncode("9am"));    
      webClient.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString(); 
      webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted); 
      webClient.UploadStringAsync(uri, "POST", postData.ToString()); 

在这里,我得到的服务器错误side..while张贴在客户端应用程序中的数据意思是在服务器端数据获取空(null)值。如何解决这个问题?

回答

相关问题