开发者

how to use MessageParameterAttribute in wcf

I wanted to know what is the use of MessageParamete开发者_如何学CrAttribute in wcf.

In my function:

[OperationContract]
public float GetAirfare(
[MessageParameter(Name=”fromCity”)] string originCity,
[MessageParameter(Name=”toCity”)] string destinationCity);

I dont use fromCity or toCity anywhere in the implementation or even while using a service. Then whats the point in giving it a name?


This attribute is used to control serialization. It can be particularly useful when you want to use a keyword or type name in the resulting XSD schema that describes an incoming message. Likewise, you can control the XML element name for the return value in a response message. It can also be a useful attribute for standardizing on XML element naming conventions, separate from CLR naming conventions. For example, you may prefer to use camel case for parameter names and Pascal case for XML.

If we were to use your provided code snippet as an example, the request would look like:

<s:Body>
    <GetAirFare xmlns="yournamespacehere">
        <fromCity>Chicago</fromCity>
        <toCity>Las Vegas</toCity>
    </GetAirFare>
</s:Body>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜