2
我想要使用xml來使用restful web服務。我爲了創造一個有效的請求來創建這個模板:帶自定義命名空間的XmlSerializer
<WS_IN_GetAccountCredit xmlns="http://schemas.datacontract.org/2004/07/WcfWebService">
<GetAccountCreditParams>
<Password>String content</Password>
<UserName>String content</UserName>
</GetAccountCreditParams>
<WSIdentity>
<WS_PassWord>String content</WS_PassWord>
<WS_UserName>String content</WS_UserName>
</WSIdentity>
</WS_IN_GetAccountCredit>
我的串行方法是這樣的:
XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces();
xmlNameSpace.Add("", "http://schemas.datacontract.org/2004/07/WcfWebService");
XmlSerializer xmlSerializer = new XmlSerializer(instance.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, instance, xmlNameSpace); ; return textWriter.ToString();
}
我的輸出是這樣的:
<?xml version="1.0" encoding="utf-16"?>
<WS_IN_GetAccountCredit xmlns:xmlns="http://schemas.datacontract.org/2004/07/WcfWebService">
<WSIdentity>
<WS_UserName>String content</WS_UserName>
<WS_PassWord>String content</WS_PassWord>
</WSIdentity>
<GetAccountCreditParams>
<UserName>String content</UserName>
<Password>String content</Password>
</GetAccountCreditParams>
</WS_IN_GetAccountCredit>
正如你可以看到,命名空間和xml版本格式不正確。我還發現this,this和this文章,但他們都不能解決我的問題。
如何建立一個有效的請求?
可以顯示''WS_IN_GetAccountCredit怎麼樣子? –
是的詛咒:您在這裏: public class WS_IN_GetAccountCredit { private WS_IN_WebServiceIdentity wsIdentity; private WS_IN_GetAccountCreditParams getAccountCreditParams; 公共WS_IN_WebServiceIdentity WSIdentity { 集合{this.wsIdentity =值; } get {return this.wsIdentity; }} 公共 WS_IN_GetAccountCreditParams GetAccountCreditParams { 集合{this.getAccountCreditParams =值; } get {return this.getAccountCreditParams; } } – David
您也可以使用'XmlElement'' Order'屬性來設置序列。 –