我有一个 webservice,它在我的项目中被 webreference 引用。
以下是 wsdl 文件中枚举的描述:
<xs:simpleType name="photoIdType">
<xs:restriction base="xs:string">
<xs:enumeration value="DRV"/>
<!-- drivers license -->
<xs:enumeration value="PAS"/>
<!-- passport -->
<xs:enumeration value="STA"/>
<!-- state ID -->
<xs:enumeration value="GOV"/>
<!-- government id -->
<xs:enumeration value="ALN"/>
<!-- alien id -->
</xs:restriction>
</xs:simpleType>
当我必须给出这个变量的值时,这是我的方式:
switch (xRootNode.Element(TagsXML.MG_T_SENDER_PHOTO_ID_TYPE).Value)
{
case "ALN":
sendRequest.senderPhotoIdType = photoIdType.ALN;
break;
case "DRV":
sendRequest.senderPhotoIdType = photoIdType.DRV;
break;
case "GOV":
sendRequest.senderPhotoIdType = photoIdType.GOV;
break;
case "PAS":
sendRequest.senderPhotoIdType = photoIdType.PAS;
break;
case "STA":
sendRequest.senderPhotoIdType = photoIdType.STA;
break;
}
就在我调用 webservice 的方法之前,我检查了我的 enum 的值。值(value)就在这里,很好。
但是当我使用 Fiddler(http 数据包分析器)检查发送到 webservice 的 Soap 请求时,photoIdType 节点不在!
您知道这是否是 Visual Studio 的已知问题吗?
你知道为什么不发送枚举值吗?
如果您需要,我可以提供更多信息。
最佳答案
我刚刚遇到了同样的问题,终于找到了答案。如果您查看生成的 sendRequest
定义,你会发现senderPhotoIdType
Specified
那是一个 bool 值。当您为 senderPhotoIdType
设置值时您需要设置 senderPhotoIdTypeSpecified
至 true
用于要序列化和传递的值。
(在这个古老的帖子中找到了答案 http://social.msdn.microsoft.com/forums/en-US/netfxremoting/thread/616f67f8-bf11-46e3-b705-41940dcafab6)
关于web-services - 枚举值未在soap请求中传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5981357/