IServiceContractGenerationExtension.GenerateContract Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Implement to modify the code document object model prior to the contract generation process.
public:
void GenerateContract(System::ServiceModel::Description::ServiceContractGenerationContext ^ context);
public void GenerateContract (System.ServiceModel.Description.ServiceContractGenerationContext context);
abstract member GenerateContract : System.ServiceModel.Description.ServiceContractGenerationContext -> unit
Public Sub GenerateContract (context As ServiceContractGenerationContext)
Parameters
- context
- ServiceContractGenerationContext
The code generated context to use to modify the code document prior to generation.
Examples
The following code example shows how to add an IServiceContractGenerationExtension to the ContractDescription.Behaviors property during the call to ImportContract.
public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
{
Console.Write("ImportContract");
// Contract Documentation
if (context.WsdlPortType.Documentation != null)
{
context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.Documentation));
}
// Operation Documentation
foreach (Operation operation in context.WsdlPortType.Operations)
{
if (operation.Documentation != null)
{
OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
if (operationDescription != null)
{
operationDescription.Behaviors.Add(new WsdlDocumentationImporter(operation.Documentation));
}
}
}
}
The following code examples show the implementation of GenerateContract that adds comments to the code generated for a service contract.
public void GenerateContract(ServiceContractGenerationContext context)
{
Console.WriteLine("In generate contract.");
context.ContractType.Comments.AddRange(Formatter.FormatComments(commentText));
}
The following code example shows the generated comments on the service contract.
/// From WSDL Documentation:
///
/// <summary>The string for the Name data member.</summary>
///
[System.Runtime.Serialization.DataMemberAttribute()]
public string Name
{
get
{
return this.NameField;
}
set
{
this.NameField = value;
}
}
'''From WSDL Documentation:
'''
'''<summary>The string for the Name data member.</summary>
'''
<System.Runtime.Serialization.DataMemberAttribute()> _
Public Property Name() As String
Get
Return Me.NameField
End Get
Set
Me.NameField = value
End Set
End Property
Remarks
Use the System.ServiceModel.Description.ServiceContractGenerationContext to modify the contract, operations, or the System.ServiceModel.Description.ServiceContractGenerator prior to code generation.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기