.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > Implementation of IWsdlExportExtension.ExportContract
Ask a questionAsk a question
 

AnswerImplementation of IWsdlExportExtension.ExportContract

  • Monday, July 03, 2006 11:15 PMR Raghu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Wednesday, July 05, 2006 7:43 PMR Raghu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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:element name="GetCustomer">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element minOccurs="0" name="searchInfo" nillable="true" xmlns:q1="http://schemas.datacontract.org/2004/07/WCF.Service" type="q1:CustomerSearch" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
    - <xs:element name="GetCustomerResponse">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element minOccurs="0" name="GetCustomerResult" nillable="true" xmlns:q2="http://schemas.datacontract.org/2004/07/WCF.Service" type="q2:Customer" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </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

  • Wednesday, July 05, 2006 7:43 PMR Raghu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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:element name="GetCustomer">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element minOccurs="0" name="searchInfo" nillable="true" xmlns:q1="http://schemas.datacontract.org/2004/07/WCF.Service" type="q1:CustomerSearch" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
    - <xs:element name="GetCustomerResponse">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element minOccurs="0" name="GetCustomerResult" nillable="true" xmlns:q2="http://schemas.datacontract.org/2004/07/WCF.Service" type="q2:Customer" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </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
  • Tuesday, August 15, 2006 12:09 AMBFC Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Tuesday, August 15, 2006 6:39 AMChristian WeyerMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    While you are at it, pls also feel free to send it over to christian.weyer AT_NOSPAM thinktecture.com

    Cheers,
  • Saturday, September 16, 2006 9:00 AMSaravana Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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.

     

  • Saturday, September 16, 2006 9:51 AMSaravana Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I found how to do it. i will post my code soon here.

    Thanks

    Saravana

  • Sunday, October 01, 2006 10:31 PMBFC Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

     

     

  • Wednesday, February 07, 2007 9:11 AMSureshM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Saravana

    Can you tell me how to do minOccurs=1 and Nilable=false

    Can you post the sample code.

    Thanks,

    Suresh M

     

  • Wednesday, March 14, 2007 4:24 PMliorhg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

    I'm also looking for a way to edit the generated schemas... Could you please post your code?

    Thanks Lior