Implementation of IWsdlExportExtension.ExportContract
- The DataMember attribute by default makes the member nillable. Since the EmitDefault is not available in beta2, I am trying to figure out how I can do this by intercepting the ExportContract method of IWsdlExportExtension in IContractBehavior implementation. But it is not clear where and how I can modify the generated WSDL. I was able to get my implementation invoked when navigating to WSDL for the contract. However I am not sure about how to modify the supplied arguments to ExportContract.
I would appreciate if some can post an example code on how the wsdl is modified in this method.
Thanks.
Answers
It turned out that I needed to intercept IWsdlExportExtension.ExportEndPoint method to modify the generated XSD schema for my data contract definition. This is working now.
However when I was inspecting the operation related schema, the input argument (i.e. of user defined data contract type) is also marked with nillable = true. For example, if you have following service contract:
[ServiceContract()]
public interface MyContract2
{
[OperationContract()]
Customer GetCustomer(CustomerSearch searchInfo);
}
[DataContract]
public class CustomerSearch
{
...
}
[DataContract]
public class Customer
{
...
}
The generated xsd is:
<?xml version="1.0" encoding="utf-16" ?>- <xs:schema xmlns:tns="http://tempuri.org/" elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:import namespace="http://schemas.datacontract.org/2004/07/WCF.Service" /></xs:schema>
If I set the nillable attribute to false in the ExportEndPoint method, I still have minOccurs = 0 on the user defined data contract type (note that it is not data member but an arugment to the operation). Since minOccurs =0, one can still call this GetCustomer method with null value for CustomerSearch object. I should be able to control the minOccurs attribute declaratively (as with proposed EmitDefault attribute on data member). What I am trying to say is, there should be a way to specify (declaratively) the required input argument to be non-null value by making the minOccurs = 1 and nillable = false for a given argument on the operation contract.
Thanks
All Replies
It turned out that I needed to intercept IWsdlExportExtension.ExportEndPoint method to modify the generated XSD schema for my data contract definition. This is working now.
However when I was inspecting the operation related schema, the input argument (i.e. of user defined data contract type) is also marked with nillable = true. For example, if you have following service contract:
[ServiceContract()]
public interface MyContract2
{
[OperationContract()]
Customer GetCustomer(CustomerSearch searchInfo);
}
[DataContract]
public class CustomerSearch
{
...
}
[DataContract]
public class Customer
{
...
}
The generated xsd is:
<?xml version="1.0" encoding="utf-16" ?>- <xs:schema xmlns:tns="http://tempuri.org/" elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:import namespace="http://schemas.datacontract.org/2004/07/WCF.Service" /></xs:schema>
If I set the nillable attribute to false in the ExportEndPoint method, I still have minOccurs = 0 on the user defined data contract type (note that it is not data member but an arugment to the operation). Since minOccurs =0, one can still call this GetCustomer method with null value for CustomerSearch object. I should be able to control the minOccurs attribute declaratively (as with proposed EmitDefault attribute on data member). What I am trying to say is, there should be a way to specify (declaratively) the required input argument to be non-null value by making the minOccurs = 1 and nillable = false for a given argument on the operation contract.
Thanks- Hi,
I am trying to change my generated xsd schema and i am experiencing some problems. Can you send me your sample code to bruno.camara@agilior.pt please?
Thanks in advance - While you are at it, pls also feel free to send it over to christian.weyer AT_NOSPAM thinktecture.com
Cheers, Hi Raghu,
I am also trying to do something similar to this. But i dont how to access XSD contents from ExportEndPoint method. I could access whole WSDL contents and schema includes. However, from schema includes i couldnt access the actual schemas. I need to modify the generated XSDs .
Could you please share you complete code here or send it to me saravana at extremeexperts dot com
Thanks, Saravana.
I found how to do it. i will post my code soon here.
Thanks
Saravana
Here is a post in which is explained a possible solution to make Xsd annotations with WCF
http://www.agilior.pt/blogs/bruno.camara/archive/2006/10/01/6.aspx
BFC
Hi Saravana
Can you tell me how to do minOccurs=1 and Nilable=false
Can you post the sample code.
Thanks,
Suresh M
Hi,
I'm also looking for a way to edit the generated schemas... Could you please post your code?
Thanks Lior


