我有一個對象和IAM使用xml seriliazer對象對象序列化。 serilaizing我的數據後,看起來像這樣如何序列化肥皂格式的對象並添加前綴
<?xml version="1.0" encoding="utf-8"?>
<doPaymentRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Credentials>
<accountId>101</accountId>
<userName>[email protected]</userName>
<password>1234</password>
</Credentials>
<custFirstName>santosh</custFirstName>
<custLastName>reddy</custLastName>
<ssn>1234</ssn>
<phoneNbr>1234567890</phoneNbr>
<PaymentRequest>
<ncpTranCode>10104587</ncpTranCode>
<tranType>PAY</tranType>
<Payment>
<tranAmount>100</tranAmount>
<paymentDateDate>2013-04-30</paymentDateDate>
<tenderType>C</tenderType>
</Payment>
</PaymentRequest>
<csoId>203</csoId>
<csoStCode>8974</csoStCode>
</doPaymentRequest>
但我的XML看起來應該像這樣
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://xxxxxxxxxxxx" xmlns:com="http://xxxxxxxxxxxxxxxxxx">
<soapenv:Header/>
<soapenv:Body>
<req:doPaymentRequest>
<req:credentials>
<com:accountId>*********</com:accountId>
<com:userName>*********</com:userName>
<com:password>*********</com:password>
</req:credentials>
<req:custFirstName>Test</req:custFirstName>
<!-- Optional: -->
<req:custMiddleName>Test</req:custMiddleName>
<req:custLastName>Test</req:custLastName>
<req:ssn>7895</req:ssn>
<!-- Optional: -->
<req:phoneNbr>1234567890</req:phoneNbr>
<req:paymentRequest>
<req:ncpTranCode>10104587</req:ncpTranCode>
<req:tranType>PAY</req:tranType>
<req:payment>
<req:tranAmount>100</req:tranAmount>
<req:paymentDateDate>2013-04-30</req:paymentDateDate>
<req:tenderType>C</req:tenderType>
</req:payment>
</req:paymentRequest>
<req:csoId>203</req:csoId>
<req:csoStCode>8974</req:csoStCode>
</req:doPaymentRequest>
</soapenv:Body>
</soapenv:Envelope>
如何添加前綴像REQ,融爲一體。 我正在使用XmlSerializer將我的對象轉換爲xml。 xmlSerializer.Serialize(stWriter,myobject);
是否有任何SOAP序列化的東西 ............編輯............. 我使用SoapFormatter並序列化對象並將其轉換爲字符串使用
Encoding.ASCII.GetString(memStream.GetBuffer())
然後我的字符串看起來像下面的怪異。
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<i2:doPaymentRequest id="ref-1" xmlns:i2="http://schemas.xmlsoap.org/soap/envelope/">
<_x003C_Credentials_x003E_k__BackingField href="#ref-4"/>
<_x003C_custFirstName_x003E_k__BackingField id="ref- 5">santosh</_x003C_custFirstName_x003E_k__BackingField>
<_x003C_custMiddleName_x003E_k__BackingField xsi:null="1"/>
<_x003C_custLastName_x003E_k__BackingField id="ref- 6">reddy</_x003C_custLastName_x003E_k__BackingField>
<_x003C_ssn_x003E_k__BackingField id="ref-7">1234</_x003C_ssn_x003E_k__BackingField>
<_x003C_phoneNbr_x003E_k__BackingField id="ref- 8">1234567890</_x003C_phoneNbr_x003E_k__BackingField>
<_x003C_PaymentRequest_x003E_k__BackingField href="#ref-9"/>
<_x003C_csoId_x003E_k__BackingField id="ref- 10">203</_x003C_csoId_x003E_k__BackingField>
<_x003C_csoStCode_x003E_k__BackingField id="ref- 11">8974</_x003C_csoStCode_x003E_k__BackingField>
</i2:doPaymentRequest>
<a1:credentials id="ref-4" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/MemoService/MemoService%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_accountId_x003E_k__BackingField id="ref- 12">101</_x003C_accountId_x003E_k__BackingField>
<_x003C_userName_x003E_k__BackingField id="ref-13">[email protected]</_x003C_userName_x003E_k__BackingField>
<_x003C_password_x003E_k__BackingField id="ref-14">1234</_x003C_password_x003E_k__BackingField>
</a1:credentials>
<a1:paymentRequest id="ref-9" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/MemoService/MemoService%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_ncpTranCode_x003E_k__BackingField id="ref- 15">10104587</_x003C_ncpTranCode_x003E_k__BackingField>
<_x003C_tranType_x003E_k__BackingField id="ref- 16">PAY</_x003C_tranType_x003E_k__BackingField>
<_x003C_Payment_x003E_k__BackingField href="#ref-17"/>
</a1:paymentRequest>
<a1:payment id="ref-17" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/MemoService/MemoService%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_tranAmount_x003E_k__BackingField id="ref- 18 ">100</_x003C_tranAmount_x003E_k__BackingField>
<_x003C_paymentDateDate_x003E_k__BackingField id="ref-19">2013-04-
30</_x003C_paymentDateDate_x003E_k__BackingField>
<_x003C_tenderType_x003E_k__BackingField id="ref-
20">C</_x003C_tenderType_x003E_k__BackingField>
</a1:payment>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我失去了什麼這裏...
複製你爲什麼要這麼做? ,同時查看http://stackoverflow.com/a/3256887/87956。仍然想要你想要做什麼。 –
你爲什麼想要這樣做?你將如何處理XML?發送到服務?那麼爲什麼不直接使用服務參考來發送呢? –
我的服務將調用另一個服務(可以說第三方服務)。這第三方服務將採用xml我的服務將返回作爲input.and此xml存儲在數據庫中,因爲它是。這種格式的xml和這種格式因此我必須使用Soapfomatter將我的對象序列化爲此SOAP格式 – Santosh