Problems making a string property mandatory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

    Problems making a string property mandatory

    Hi,

    I am developing a web service for a customer. The service has a method, that
    returns an array of Forms. Each form has a Name property of Type String.

    The customer wants the contract to specify, thath the name is mandatory and
    not nullable. To reflect this, they want the xml in the wsdl (the Form part)
    to look similar to this:

    <xs:complexTy pe name="Form">
    <xs:sequence>
    ...
    <xs:element minOccurs="1" maxOccurs="1" name="Name" nillable="false "
    type="xs:string " />
    ...

    So, minOccurs should be 1 and nillable should be false (or omitted), to
    ensure the value is present and not null.

    No matter how I go about this, however, I cannot make the wsdl generate the
    desired values. I have tried to do contract-first development using WSCF from
    thinktecture, and have the schema dictate the above values for minOccurs and
    nillable, but this approach has not remedied the problem.

    Is it at all possible to do what I want using .Net and Visual Studio 2005? I
    hope my problem is described adequately, otherwise please request more
    information. Any help is greatly appreciated.
  • Steven Cheng[MSFT]

    #2
    RE: Problems making a string property mandatory

    Hi,

    Regarding on the webservice class property definition problem you
    mentioned, here are some of my understanding and suggestion:

    1. .NET webservice will always generate the xsd scheme for class property
    as below:

    ** for value type(primitive types or struct), it will use minOccurs="1"
    since value type will always be assigned a value(doesn't have null value
    unless you use nullable type).

    ** for reference type(such as normal class), it will use minOccurs="0"
    since value type will always support null value, the "string" type in your
    case is just conform to this policy.

    So far this rule is not changable in our custom code(attribute) .

    2. Also, XML XSD schema definition's element definition doesn't 100%
    completely identical to .NET(or OO ) class/type definition. For example, if
    you have the following xsd schema

    <element minOccurs="1" ..../>

    you can not find a reference type to mapping it since reference type always
    support null reference value. I think you can consider define a wrapper
    class(which inherit from ValueType ), property of such type will be
    automatically generated as minOccurs="1" in XSD schema. However, you still
    need to ensure that any sub property of reference type(such as string) has
    been supplied a value in your own code.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    =============== =============== =============== =====

    Get notification to my posts through email? Please refer to
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscripti...t/default.aspx.

    =============== =============== =============== =====



    This posting is provided "AS IS" with no warranties, and confers no rights.




    Comment

    • John Saunders [MVP]

      #3
      Re: Problems making a string property mandatory

      "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
      news:9CE60739-0889-4BB6-AF49-DB9EAC6A6AC0@mi crosoft.com...
      Hi,
      >
      I am developing a web service for a customer. The service has a method,
      that
      returns an array of Forms. Each form has a Name property of Type String.
      >
      The customer wants the contract to specify, thath the name is mandatory
      and
      not nullable. To reflect this, they want the xml in the wsdl (the Form
      part)
      to look similar to this:
      >
      <xs:complexTy pe name="Form">
      <xs:sequence>
      ...
      <xs:element minOccurs="1" maxOccurs="1" name="Name" nillable="false "
      type="xs:string " />
      ...
      >
      So, minOccurs should be 1 and nillable should be false (or omitted), to
      ensure the value is present and not null.
      >
      No matter how I go about this, however, I cannot make the wsdl generate
      the
      desired values. I have tried to do contract-first development using WSCF
      from
      thinktecture, and have the schema dictate the above values for minOccurs
      and
      nillable, but this approach has not remedied the problem.
      >
      Is it at all possible to do what I want using .Net and Visual Studio 2005?
      I
      hope my problem is described adequately, otherwise please request more
      information. Any help is greatly appreciated.
      You don't need to let .NET generate the WSDL for you. Create your own WSDL
      (perhaps based on the one that .NET generates) and then use that.
      --
      John Saunders [MVP]


      Comment

      • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

        #4
        Re: Problems making a string property mandatory

        "John Saunders [MVP]" wrote:
        [...]
        You don't need to let .NET generate the WSDL for you. Create your own WSDL
        (perhaps based on the one that .NET generates) and then use that.
        --
        John Saunders [MVP]
        >
        Hi John,

        Thanks for your reply.

        That's an interesting idea; can you point me in the right direction on where
        to look for how I can use my own WSDL? I have already generated one using
        contract-first techniques, and I would very much like to use that instead of
        the .Net generated one.

        Comment

        • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

          #5
          RE: Problems making a string property mandatory

          Hi Steven,

          Thank your for replying. It would seem creating a wrapper will just "nest"
          the problem one level deeper, since the wrapper will still need a string
          property/field, that will be generated "incorrectl y" (for my present purpose)
          in the xsd.

          Is it possible to hook in to the wsdl generation process at some point to do
          some post filtering of the output or generating the wsdl entirely by custom
          code?

          "Steven Cheng[MSFT]" wrote:
          Hi,
          >
          Regarding on the webservice class property definition problem you
          mentioned, here are some of my understanding and suggestion:
          >
          1. .NET webservice will always generate the xsd scheme for class property
          as below:
          >
          ** for value type(primitive types or struct), it will use minOccurs="1"
          since value type will always be assigned a value(doesn't have null value
          unless you use nullable type).
          >
          ** for reference type(such as normal class), it will use minOccurs="0"
          since value type will always support null value, the "string" type in your
          case is just conform to this policy.
          >
          So far this rule is not changable in our custom code(attribute) .
          >
          2. Also, XML XSD schema definition's element definition doesn't 100%
          completely identical to .NET(or OO ) class/type definition. For example, if
          you have the following xsd schema
          >
          <element minOccurs="1" ..../>
          >
          you can not find a reference type to mapping it since reference type always
          support null reference value. I think you can consider define a wrapper
          class(which inherit from ValueType ), property of such type will be
          automatically generated as minOccurs="1" in XSD schema. However, you still
          need to ensure that any sub property of reference type(such as string) has
          been supplied a value in your own code.
          >
          Sincerely,
          >
          Steven Cheng
          >
          Microsoft MSDN Online Support Lead
          >
          >
          >
          =============== =============== =============== =====
          >
          Get notification to my posts through email? Please refer to
          Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

          ications.
          >
          >
          >
          Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
          where an initial response from the community or a Microsoft Support
          Engineer within 1 business day is acceptable. Please note that each follow
          up response may take approximately 2 business days as the support
          professional working with you may need further investigation to reach the
          most efficient resolution. The offering is not appropriate for situations
          that require urgent, real-time or phone-based interactions or complex
          project analysis and dump analysis issues. Issues of this nature are best
          handled working with a dedicated Microsoft Support Engineer by contacting
          Microsoft Customer Support Services (CSS) at
          http://msdn.microsoft.com/subscripti...t/default.aspx.
          >
          =============== =============== =============== =====
          >
          >
          >
          This posting is provided "AS IS" with no warranties, and confers no rights

          Comment

          • John Saunders [MVP]

            #6
            Re: Problems making a string property mandatory

            "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
            news:CA6F4F32-5392-4310-A629-FB670D98A0B0@mi crosoft.com...
            "John Saunders [MVP]" wrote:
            [...]
            >You don't need to let .NET generate the WSDL for you. Create your own
            >WSDL
            >(perhaps based on the one that .NET generates) and then use that.
            >--
            >John Saunders [MVP]
            >>
            Hi John,
            >
            Thanks for your reply.
            >
            That's an interesting idea; can you point me in the right direction on
            where
            to look for how I can use my own WSDL? I have already generated one using
            contract-first techniques, and I would very much like to use that instead
            of
            the .Net generated one.
            Sorry, use it for what? Give it to your clients. Tell them to point to the
            WSDL instead of using "?WSDL".
            --
            John Saunders [MVP]


            Comment

            • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

              #7
              Re: Problems making a string property mandatory

              I'm sorry, it seems I know to little about this to ask the right questions.

              I just thought that if my client pointed to the Wsdl file, the web service
              itself would still allow incorrect data (that will not validate against the
              schema) in the Form object. Are you saying that's not an issue at all?

              I would rather the check occurred via the schema, so I will not have to
              check for validity on multiple levels. I would hate to have a situation where
              changes needed to be reflected in more than one place (i.e. both in the Wsdl
              and in the OO objects).

              Thank you for your help.

              /Mads Nielsen

              "John Saunders [MVP]" wrote:
              "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
              news:CA6F4F32-5392-4310-A629-FB670D98A0B0@mi crosoft.com...
              "John Saunders [MVP]" wrote:
              [...]
              You don't need to let .NET generate the WSDL for you. Create your own
              WSDL
              (perhaps based on the one that .NET generates) and then use that.
              --
              John Saunders [MVP]
              >
              Hi John,

              Thanks for your reply.

              That's an interesting idea; can you point me in the right direction on
              where
              to look for how I can use my own WSDL? I have already generated one using
              contract-first techniques, and I would very much like to use that instead
              of
              the .Net generated one.
              >
              Sorry, use it for what? Give it to your clients. Tell them to point to the
              WSDL instead of using "?WSDL".
              --
              John Saunders [MVP]
              >
              >
              >

              Comment

              • John Saunders [MVP]

                #8
                Re: Problems making a string property mandatory

                "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
                news:78217E22-EA80-4F00-A832-3A238CAC72EE@mi crosoft.com...
                I'm sorry, it seems I know to little about this to ask the right
                questions.
                >
                I just thought that if my client pointed to the Wsdl file, the web service
                itself would still allow incorrect data (that will not validate against
                the
                schema) in the Form object. Are you saying that's not an issue at all?
                >
                I would rather the check occurred via the schema, so I will not have to
                check for validity on multiple levels. I would hate to have a situation
                where
                changes needed to be reflected in more than one place (i.e. both in the
                Wsdl
                and in the OO objects).
                Oh, I see. Check out this article in MSDN. It's a bit advanced, but you may
                be able to copy/paste the code: Web Services: Extend the ASP.NET WebMethod
                Framework by Adding XML Schema Validation
                (http://msdn.microsoft.com/msdnmag/is.../default.aspx).
                --
                John Saunders [MVP]


                Comment

                • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

                  #9
                  Re: Problems making a string property mandatory

                  This is great stuff and will definitely solve my validation concerns, thanks
                  alot!

                  Do you know if there a similar hooks that I can use, so my service will
                  return the manually crafted Wsdl file when invoked with "?wsdl" instead of
                  the generated one?

                  /Mads Nielsen

                  "John Saunders [MVP]" wrote:
                  "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
                  news:78217E22-EA80-4F00-A832-3A238CAC72EE@mi crosoft.com...
                  I'm sorry, it seems I know to little about this to ask the right
                  questions.

                  I just thought that if my client pointed to the Wsdl file, the web service
                  itself would still allow incorrect data (that will not validate against
                  the
                  schema) in the Form object. Are you saying that's not an issue at all?

                  I would rather the check occurred via the schema, so I will not have to
                  check for validity on multiple levels. I would hate to have a situation
                  where
                  changes needed to be reflected in more than one place (i.e. both in the
                  Wsdl
                  and in the OO objects).
                  >
                  Oh, I see. Check out this article in MSDN. It's a bit advanced, but you may
                  be able to copy/paste the code: Web Services: Extend the ASP.NET WebMethod
                  Framework by Adding XML Schema Validation
                  (http://msdn.microsoft.com/msdnmag/is.../default.aspx).
                  --
                  John Saunders [MVP]
                  >
                  >
                  >

                  Comment

                  • John Saunders [MVP]

                    #10
                    Re: Problems making a string property mandatory

                    "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
                    news:3304A90A-E137-4D11-B002-228FAB801B32@mi crosoft.com...
                    This is great stuff and will definitely solve my validation concerns,
                    thanks
                    alot!
                    >
                    Do you know if there a similar hooks that I can use, so my service will
                    return the manually crafted Wsdl file when invoked with "?wsdl" instead of
                    the generated one?
                    I don't yet have a complete answer for that. I have to answer it for myself,
                    as well.

                    In the meantime, I'm going to suggest to you what I'm going to suggest for
                    my situation: put the .wsdl file "next to" the service. In addition to
                    http://server/Service.asmx, have http://server/Service.wsdl. You'll just
                    have to make sure that IIS is configured to pass the .wsdl extension to
                    ASP.NET, and you'll have to configure the HttpHandler to serve it up. I
                    forget the name of the correct handler, maybe FileHttpHandler or something?
                    --
                    John Saunders [MVP]


                    Comment

                    • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

                      #11
                      Re: Problems making a string property mandatory

                      Thanks for the answer, I will try that.

                      /Mads Nielsen

                      "John Saunders [MVP]" wrote:
                      "Mads Nielsen" <ResultmakerMSD N@newsgroups.no spamwrote in message
                      news:3304A90A-E137-4D11-B002-228FAB801B32@mi crosoft.com...
                      This is great stuff and will definitely solve my validation concerns,
                      thanks
                      alot!

                      Do you know if there a similar hooks that I can use, so my service will
                      return the manually crafted Wsdl file when invoked with "?wsdl" instead of
                      the generated one?
                      >
                      I don't yet have a complete answer for that. I have to answer it for myself,
                      as well.
                      >
                      In the meantime, I'm going to suggest to you what I'm going to suggest for
                      my situation: put the .wsdl file "next to" the service. In addition to
                      http://server/Service.asmx, have http://server/Service.wsdl. You'll just
                      have to make sure that IIS is configured to pass the .wsdl extension to
                      ASP.NET, and you'll have to configure the HttpHandler to serve it up. I
                      forget the name of the correct handler, maybe FileHttpHandler or something?
                      --
                      John Saunders [MVP]
                      >
                      >
                      >

                      Comment

                      • Steven Cheng[MSFT]

                        #12
                        RE: Problems making a string property mandatory

                        Hi,

                        For customize the ASP.NET autogenerated wsdl document, one way is to supply
                        a custom wsdl document completely authored by ourselves through the binding
                        setting:

                        Expert-led tech and creative training to master your craft. Unlimited and online.


                        Here are some other information about other configuration about customize
                        ASP.NET webservice's WSDL generation:

                        #Configuring WSDL File Generation for ASP.NET Web Services
                        Microsoft technical documentation for older versions of products, services and technologies.



                        Sincerely,

                        Steven Cheng

                        Microsoft MSDN Online Support Lead


                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        Comment

                        • Steven Cheng[MSFT]

                          #13
                          Re: Problems making a string property mandatory

                          Hi Mads,

                          How are you doing on this issue, do you get any progress? Or does the
                          information about provide custom WSDL document in ASP.NET webservice in
                          ther other reply also helps some? If you still have anything need help,
                          please feel free to post here.

                          Sincerely,

                          Steven Cheng

                          Microsoft MSDN Online Support Lead


                          This posting is provided "AS IS" with no warranties, and confers no rights.

                          Comment

                          • =?Utf-8?B?TWFkcyBOaWVsc2Vu?=

                            #14
                            Re: Problems making a string property mandatory

                            I am getting there. Currently I have created an HttpModule which handles
                            requests for ?wsdl and ?disco and redirects to the manually altered wsdl file.

                            I have added the following to web.config:
                            <appSettings>
                            <!--
                            Determines if ?wsdl for the service gets redirected to the maunally
                            edited .wsdl file.
                            If the setting is present specify all pages that get redirected
                            (separated by semicolon)
                            as value, e.g.: value="Service1 .asmx;Service2. asmx;..."
                            -->
                            <add
                            key="RedirectWs dl"
                            value="DataExtr act.asmx"/>
                            </appSettings>
                            [...]
                            <system.web>
                            <httpModules>
                            <add type="Resultmak er.Dia.Webservi ces.AsmxHelpMod ule,
                            Resultmaker.Dia .Webservices"
                            name="AsmxHelpM odule" />
                            </httpModules>

                            I have then created the module as follows:

                            public class AsmxHelpModule : IHttpModule {
                            private AsmxHelpModule( ) {}
                            void Application_Beg inRequest(objec t sender, System.EventArg s e) {
                            string requestPath = HttpContext.Cur rent.Request.Ra wUrl;
                            requestPath = requestPath.Tri m();
                            requestPath = requestPath.ToL ower();
                            string setting = ConfigurationMa nager.AppSettin gs["RedirectWs dl"];
                            if (((setting != null) && (setting != ""))) {
                            setting = setting.ToLower ();
                            string[] fileNames = setting.Split(' ;');
                            for (int i = 0; i != fileNames.Lengt h; ++i) {
                            string fn = fileNames[i];
                            if (((requestPath. IndexOf((fn + "?wsdl")) 0)
                            || (requestPath.In dexOf((fn + "?disco")) >
                            0))) {

                            HttpContext.Cur rent.Server.Tra nsfer("DataExtr act.wsdl", false);
                            return;
                            }
                            }
                            }
                            }
                            public virtual void Init(HttpApplic ation app) {
                            app.BeginReques t += new
                            System.EventHan dler(this.Appli cation_BeginReq uest);
                            }
                            [...]
                            }

                            I hope this may help others with similar problems.

                            /Mads Nielsen

                            "Steven Cheng[MSFT]" wrote:
                            Hi Mads,
                            >
                            How are you doing on this issue, do you get any progress? Or does the
                            information about provide custom WSDL document in ASP.NET webservice in
                            ther other reply also helps some? If you still have anything need help,
                            please feel free to post here.
                            >
                            Sincerely,
                            >
                            Steven Cheng
                            >
                            Microsoft MSDN Online Support Lead
                            >
                            >
                            This posting is provided "AS IS" with no warranties, and confers no rights

                            Comment

                            • Steven Cheng[MSFT]

                              #15
                              Re: Problems making a string property mandatory

                              Thanks for your followup and share the result.

                              If you have interest, you can also have a look at the "WebServiceBind ing"
                              approach for provide custom wsdl:

                              Expert-led tech and creative training to master your craft. Unlimited and online.


                              Sincerely,

                              Steven Cheng

                              Microsoft MSDN Online Support Lead


                              This posting is provided "AS IS" with no warranties, and confers no rights.

                              Comment

                              Working...