我有一个WCF服务。我使用带有jQuery的SOAP 1.2来调用它的方法 我调用一个方法,假设返回以下类:
namespace ConfigComWrapper.ConfigCom
{
public class CommandResult
{
public int ErrorCode = ErrorCodeTypes.OK;
public string ErrorDescription = string.Empty;
public CommandResult(){}
}
然而,SOAP响应只返回其成员,甚至根本没有提到CommandResult类。这是WCF测试客户端中生成的xml响应(SOAP):
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1" u:Id="_2">http://www.enghouse.com/CosmoCom/WebAdminAPIServiceLibrary/ITenantAdmin/LoginResponse</a:Action>
<a:RelatesTo u:Id="_3">urn:uuid:509fa011-0e6a-4370-896b-6d45756a5fa9</a:RelatesTo>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="uuid-71549a1a-6c54-4a76-b224-66bc45877e0f-11">
<u:Created>2012-10-18T14:30:49.878Z</u:Created>
<u:Expires>2012-10-18T14:35:49.878Z</u:Expires>
</u:Timestamp>
<c:DerivedKeyToken u:Id="uuid-71549a1a-6c54-4a76-b224-66bc45877e0f-7" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
<o:SecurityTokenReference>
<o:Reference URI="urn:uuid:cf569488-040b-4bcb-8270-b7973c0d6e2a" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" />
</o:SecurityTokenReference>
<c:Offset>0</c:Offset>
<c:Length>24</c:Length>
<c:Nonce>TNFiG8+NqEdgXJ8njmVNPw==</c:Nonce>
</c:DerivedKeyToken>
<c:DerivedKeyToken u:Id="uuid-71549a1a-6c54-4a76-b224-66bc45877e0f-8" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
<o:SecurityTokenReference>
<o:Reference URI="urn:uuid:cf569488-040b-4bcb-8270-b7973c0d6e2a" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" />
</o:SecurityTokenReference>
<c:Nonce>9dmn1BiWfn0U7cmlbkFWdg==</c:Nonce>
</c:DerivedKeyToken>
<e:ReferenceList xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:DataReference URI="#_1" />
<e:DataReference URI="#_4" />
</e:ReferenceList>
<e:EncryptedData Id="_4" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<o:SecurityTokenReference>
<o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#uuid-71549a1a-6c54-4a76-b224-66bc45877e0f-8" />
</o:SecurityTokenReference>
</KeyInfo>
<e:CipherData>
<e:CipherValue>CgnkLBEkjO1Pnqsypzy4NCQUs0E7f0gEMepzaMacN1Zkrfvqldi+sdFDOPHehXwdIa6h7OXiqCHCCTNuQMP0kmQaqrX3YqeeUi1ntlZdOJU1X0s7bwavxJHWHfP0w1ASrOo6a0YOK3o750uO9dgbp/T69dRGZW0/oRKZu0eES5URJkAx5NuHGGKUP9gb+RraOu+1wwJnAvpiuSe2G/SULwVGjQzu3SdRn5HA3BU5Ndh1qnq1n6TLXRByPeNTrSUMs6CV1jNN+EiNrtNeinre6nCE2WRuNvBaomcZW+5h0tx7r7Jg/DlLKK1YLvJVB4jDjtf/9eh1CWTgHiq7mrZev9aL0WYkwX2coMn6NO+vyMD0EKobkHM3zTf7okFDwVg8yWCYOGXO3zhWXivcPl1M2XYqzQWSmXtvVAN7kKyktjiB3SLGSq1jpo13fXuoII+K/yngJH4We/qoyjUSllTZDz9TBS7aUielDhL2nJZIjTGfBNw6HEYJsp2xaZOojrcRRvrKGNKRifYJX0moP1GT8J3EzRkgVAyhI9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u2OdpxFJxAXR+p4Lv4PkjQGrPTUAUv0lqZNCTRKoTreszpIAlKcVTNKnRgKCMc2PhzJidZ6jJcuBbWxuVkVmguoUg4TujvOKxYJPUk5XBcuO0c7xr+78lYQ2KzHrliVyYUFNY9m7mM2b/g+bbIgJqj3v80fOpSKRiTqfdnwoFVPKZFIprgN4eDOatghzce/ZAQyrwwnya0Gq5Z/msJdRQAklKYrfJG8E6FYssCJCCuvrsaVHwjmzzSwmnA2XoYrK3QhhPsNhI6O0mlLbh4ALo7YwOkrf2+jacf5zpeui1bTnFo4coknvFEcC8CCMymAzrLtLWqBkAbdCh0bCTd/9F+Upyiwk/dWgkPk4trnYe6yyxnKaiqxsUZ4jruo+jmjYb45s1mig5YGV2kh+z/fNf6bhHSseANqPQJAOLdyC7sRIP5LdALtxIzpkF21ZOJ78FShTY9PV7XvUywNOubXGpMo0ljhC5Y4Sx6UC0LBcg7gb66NaqrsLR8kObjnhK2WUHdFZsvBckb4VzkG8TRRAIUcQXRbwLKrA9yl</e:CipherValue>
</e:CipherData>
</e:EncryptedData>
</o:Security>
</s:Header>
<s:Body u:Id="_0">
<LoginResponse xmlns="http://www.enghouse.com/CosmoCom/WebAdminAPIServiceLibrary">
<LoginResult xmlns:a="http://schemas.datacontract.org/2004/07/ConfigComWrapper.ConfigCom" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ErrorCode>0</a:ErrorCode>
<a:ErrorDescription />
</LoginResult>
</LoginResponse>
</s:Body>
</s:Envelope>
但由于某种原因,WCF测试客户端中的“格式化选项”显示返回了CommandResult:
有人知道为什么它缺少SOAP Response中的CommandResult类吗? 谢谢!
答案 0 :(得分:0)
如果由于服务器端的操作调用而发送对象,则必须将类设置为[DataContract]。根据我的理解,这将有助于自定义类的序列化, 根据您的问题,您必须将其设置如下。
namespace ConfigComWrapper.ConfigCom
{
[DataContract]
public class CommandResult
{
[DataMember]
public int ErrorCode = ErrorCodeTypes.OK;
[DataMember]
public string ErrorDescription = string.Empty;
[DataMember]
public CommandResult(){}
}
完成此操作后,请在客户端更新服务参考。希望这会帮助你。