开发者

how to use MessageParameterAttribute in wcf

开发者 https://www.devze.com 2022-12-30 04:04 出处:网络
I wanted to know what is the use of MessageParamete开发者_如何学CrAttribute in wcf. In my function:

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

精彩评论

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