2012-01-06 2 views
3

입력란의 값을 내 webservice에 게시해야합니다. 인터넷에서 검색하면 운이 전혀 없습니다. AJAX/JSon을 사용하여 WCF를 통해서만 데이터를 랩핑하고 게시 할 수 없습니다. 그리고 나는 그것에 매달렸다. 누군가가 도울 수 있기를 바랍니다.양식 작업을 통해 데이터를 전달하는 방법 - WebService (WCF)의 "POST"?

HTML 파일 :
공간 소비를 최소화하기 위해 일부 필드를 제거합니다.

<%@ Page Language="C#" AutoEventWireup="ue" CodeBehind="WebForm1.aspx.cs" Inherits="BasePayment.Client.WebForm1" %> 

<!DOCTYPE html PUBLIC "-//W3C//D HTML 4.01 ansitional//EN" "http://www.w3.org//html4/loose.d"> 
<html> 
<body> 
<form method="POST" name="frmPayment" action=""> 

Merchant ID 
<input type="text" name="merchantId" value="1546" /> 

Payment Method 
<input type="text" name="pMethod" value="VISA" /> 

Credit card expiry month - 2 digits. 
<input type="text" name="epMonth" value="02" /> 

Credit card expiry year - 4 digits. 
<input type="text" name="epYear" value="2012" /> 

Credit card number. 
<input type="text" name="cardNo" value="4918914107195005" /> 

Credit Card Verification Code 
<input type="text" name="securityCode" value="123" /> 

Credit card holder name 
<input type="text" name="cardHolder" value="Juan Dela Cruz" /> 

Redirect to a URL upon failed ansaction: 
<input type="text" name="failUrl" value="http://www.yahoo.com" /> 

Remark: 
<input type="text" name="remark" value="Other Remarks" /> 

<input type="submit" value="Submit" id="btnSubmit"/> 

</form> 
</body> 
</html> 

WCF : WCF의

using System; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using BasePayment.Entities; 
using System.ServiceModel.Activation; 

namespace BasePayment.WebService 
{ 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
    public class PaymentComponent : IPaymentComponent 
    { 
     public void SendPayment(PaymentInformation payInfo) 
     { 
      PaymentInformation newPayInfo = new PaymentInformation(); 

      /*Validation of input goes here ... 
      * 
      * 
      * 
      * */ 

      // Then send data. 
     } 
    } 
} 

인터페이스 : 지불 정보를 원하시면

using System; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Web; 

using BasePayment.Entities; 

namespace BasePayment.WebService 
{ 
    [ServiceContract(Namespace="http://test.com/services/payment")] 
    public interface IPaymentComponent 
    { 
     [OperationContract] 
     [WebInvoke(UriTemplate="PaymentInfo", Method="POST")] 
     void SendPayment(PaymentInformation payInfo); 
    } 
} 

ENTITY :
내가 공간 소비를 최소화하기 위해 일부 속성을 제거합니다. ENTITY OF

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace BasePayment.Entities 
{ 
    public class PaymentInformation : IPaymentInformation 
    { 
     public PaymentInformation() 
     { 
     } 

     public int ExpiryMonth 
     { 
      get; 
      set; 
     } 

     public int ExpiryYear 
     { 
      get; 
      set; 
     } 

     public int CreditCardVerificationCode 
     { 
      get; 
      set; 
     } 

     public double Amount 
     { 
      get; 
      set; 
     } 

     public string Language 
     { 
      get; 
      set; 
     } 

     public string CardHolderName 
     { 
      get; 
      set; 
     } 

     public string Remark 
     { 
      get; 
      set; 
     } 

    } 
} 

INTERFACE : HERE

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace BasePayment.Entities 
{ 
    interface IPaymentInformation 
    { 
     long CreditCardNumber { get; set; } 
     long OrderReferenceID { get; set; } 

     int CurrencyCode { get; set; } 
     int MerchantID { get; set; } 
     int ExpiryMonth { get; set; } 
     int ExpiryYear { get; set; } 
     int CreditCardVerificationCode { get; set; } 

     double Amount { get; set; } 

     string Language { get; set; } 
     string CardHolderName { get; set; } 
     string URLUponFailed { get; set; } 
     string URLUponSuccess { get; set; } 
     string URLUponError { get; set; } 
     string Remark { get; set; } 

     PaymentMethod PaymentMethod { get; set; } 
    } 
} 

AND 내 프로젝트 PREVIEW이다 미리

enter image description here

감사 !!!

+0

나는 묻지 않아도됩니다. 왜 WCF 서비스를 사용해야하나요? 왜 서버 측 코드에 다시 게시하고 유효성 검사/처리를 수행하지 않습니까? – Steve

+0

'서버에 다시 게시'한다는 것은 무엇을 의미합니까? 내 주요 목표는 WCF Webservice를 사용하여 "FORM"에서 게시 된 데이터를 래핑하는 것입니다. 그것은 나에게 주어진 지시였다. 귀하의 회신에 감사드립니다. – fiberOptics

답변

1

이 경우 WebForm1.aspx.cs가 될 서버 측 코드에 다시 입력을 게시하면 입력을 runat = "server"로 설정하거나 다음과 같은 aspx 컨트롤을 사용합니다. 다음 :

<asp:TextBox runat="server" id="merchantId" value="1546" /> 

모든 입력에 대해이 작업을 수행해야합니다. 그런 다음 페이지로드 방법 당신은 갈 수 :

protected void Page_Load(object sender, EventArgs e) 
    { 
     if(this.IsPostBack) 
     { 
      PaymentInformation newPayInfo = new PaymentInformation(); 
      newPayInfo.MerchantID = merchantId.Text; // to get text 
      /* Validation of input goes here ... */ 
      // Then send data. 
     } 
    } 

을 방금 페이지를 사용할 수 있습니다 WCF를 사용할 필요가없는 것을 의미한다.

희망이 있으리라 생각합니다.

+0

좋은 지적이 있습니다. 하지만 WCF의 HTTPOST를 사용하여 데이터를 전달해야합니다. – fiberOptics

관련 문제