本文整理汇总了C#中Response.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Response.AddAttribute方法的具体用法?C# Response.AddAttribute怎么用?C# Response.AddAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.AddAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBindingErrorResponse
/**
* Creates a binding error response according to the specified error code
* and unknown attributes.
*
* @param errorCode the error code to encapsulate in this message
* @param reasonPhrase a human readable description of the error
* @param unknownAttributes a char[] array containing the ids of one or more
* attributes that had not been recognized.
* @throws StunException INVALID_ARGUMENTS if one or more of the given
* parameters had an invalid value.
*
* @return a binding error response message containing an error code and a
* UNKNOWN-ATTRIBUTES header
*/
private static Response CreateBindingErrorResponse(int errorCode,
String reasonPhrase,
int[] unknownAttributes)
{
Response bindingErrorResponse = new Response();
bindingErrorResponse.SetMessageType(Message.BINDING_ERROR_RESPONSE);
//init attributes
UnknownAttributesAttribute unknownAttributesAttribute = null;
ErrorCodeAttribute errorCodeAttribute =
AttributeFactory.CreateErrorCodeAttribute(errorCode,reasonPhrase);
bindingErrorResponse.AddAttribute(errorCodeAttribute);
if(unknownAttributes != null)
{
unknownAttributesAttribute = AttributeFactory.
CreateUnknownAttributesAttribute();
for (int i = 0; i < unknownAttributes.Length; i++)
{
unknownAttributesAttribute.AddAttributeID(unknownAttributes[i]);
}
bindingErrorResponse.AddAttribute(unknownAttributesAttribute);
}
return bindingErrorResponse;
}
示例2: CreateBindingResponse
/**
* Creates a BindingResponse assigning the specified values to mandatory
* headers.
*
* @param mappedAddress the address to assign the mappedAddressAttribute
* @param sourceAddress the address to assign the sourceAddressAttribute
* @param changedAddress the address to assign the changedAddressAttribute
* @return a BindingResponse assigning the specified values to mandatory
* headers.
* @throws StunException ILLEGAL_ARGUMENT
*/
public static Response CreateBindingResponse(StunAddress mappedAddress,
StunAddress sourceAddress,
StunAddress changedAddress)
{
Response bindingResponse = new Response();
bindingResponse.SetMessageType(Message.BINDING_RESPONSE);
//mapped address
MappedAddressAttribute mappedAddressAttribute =
AttributeFactory.CreateMappedAddressAttribute(mappedAddress);
//source address
SourceAddressAttribute sourceAddressAttribute =
AttributeFactory.CreateSourceAddressAttribute(sourceAddress);
//changed address
ChangedAddressAttribute changedAddressAttribute =
AttributeFactory.CreateChangedAddressAttribute(changedAddress);
bindingResponse.AddAttribute(mappedAddressAttribute);
bindingResponse.AddAttribute(sourceAddressAttribute);
bindingResponse.AddAttribute(changedAddressAttribute);
return bindingResponse;
}