2014-01-22 3 views
-1

사이트를 만들고 있는데, 지불 게이트웨이가 있습니다. 필요한 것은 웹 서비스에 일부 C# 요소를 전달하는 것입니다. XML 파일을 출력해야합니다. 내 요소들. 어떻게해야합니까?C# 요소를 사용하여 XML을 출력하는 방법

<PaymentRequest> 
<ProductName>Match Ticket</ProductName> (Static value)                                 
<Prefix>Mr</Prefix> (Prefix of the booker)                                                  
<FirstName>Test</FirstName> (First name of the user)                                        
<LastName>Test</LastName> (Last name of the user)                                        
<Address>Test Address</Address> Address of the user(can be a dummy value in case the customer did not fill this)                                       
<City>London</City> City of user(can be a dummy value in case the customer did not fill this)                                                      
<Country>UK</Country> Country of user(can be a dummy value in case the customer did not fill this) 
<Mobile>98231283123</Mobile> (user phone no)                                        
<EmailId>[email protected]</EmailId> (user email)                              
<PaymentMethod>PayatBank</PaymentMethod> (this will be the option selected)                        
<TotalAmount>13314</TotalAmount> (total amount, this is already a label)                                 

<Amount>12926</Amount> (Base amount of the booking)                                          
<GatewayCharge>388</GatewayCharge> (Credit card charges)                                
<GatewayChargeInPercent>3</GatewayChargeInPercent>                
<CallBackURL>http://www.google.com</CallBackURL>                 Link where the user will get redirected after the payment has been made. This will be used for online payments only. 
</PaymentRequest> 
+2

'PaymentRequest' 클래스를 만들고 ['XmlSerializer']로 직렬화 할 수 있습니다. (http://msdn.microsoft.com/en-us/library/system.xml.serialization.xml serializer (v = vs.110)) .aspx) –

+0

대답 주셔서 감사합니다, xmlserializer 연구해야합니다 – Kenneth

답변

0

당신은 XmlSerializer를 사용해야합니다 다음과 같이

보내야 요청입니다. 원하는 경우이 도우미를 사용할 수 있습니다.

public static class XmlSerializationHelper 
{ 
    public static string Serialize<T>(T value) 
    { 
     XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); 
     StringWriter writer = new StringWriter(); 
     xmlSerializer.Serialize(writer, value); 

     return writer.ToString(); 
    } 

    public static T Deserialize<T>(string rawValue) 
    { 
     XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); 
     StringReader reader = new StringReader(rawValue); 

     T value = (T)xmlSerializer.Deserialize(reader); 
     return value; 
    } 
} 

다음번에 조사해보십시오. 나는 이것을 찾기가 너무 어렵다고 생각하지 않는다.

나는 이것을 blog에서 가져 왔습니다. 고마워.

+0

답변을 주셔서 감사합니다,하지만 내 라디오 버튼 액션에서 이것을 어떻게 부르니? 또한 XML로 요소를 추가하는 방법은 무엇입니까? – Kenneth

+0

'PaymentRequest'를 나타내는 커스텀 클래스를 생성 할 필요가 있습니다. 위의 코드에서'T'를 볼 때마다 커스텀 클래스로 대체 할 것입니다. – dursk

+0

@Kenneth 무엇을 사용하고 계십니까? WPF 내 생각 엔? 당신은 시작하는 것 같습니다. 어쩌면이 도우미를 사용하기 전에 몇 가지 기본 사항을 배울 수 있습니다. – aloisdg

관련 문제