Avatar of ktola
ktola asked on

WSDL In Visual Studio 2010

I recently added a new ASMX/Web Service file to my ASP.NET C# website in Visual Studio 2010.  I then added all of my methods and attributes and everything appeared to work without issues.

Now, however, the WSDL is wrong - it does not have any default values and it is erroneously setting MinOccurs=0 for required fields and MinOccurs=1 for optional fields.  I know this is due to each field's ability to be null but I need to edit the WSDL to override these values.

I cannot find any way to do so and I cannot figure out how to edit this generated WSDL in Visual Studio 2010.  I need to edit the WSDL and then push it out to Production - can somebody please help me out here?
Web ServicesC#ASP.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon
Kumaraswamy R


I understnad that VS 2010 opens WSDL files but it does not then allow you to create a web service.  I used WSDL.exe based on the WSDL I wanted to generate an interface.  I then used that interface as a new web service and the .NET-generated WSDL on that new web service reverted back to the one without required fields.

I also figured out that adding [System.ComponentModel.DefaultValueAttribute()] tags to each field in a web method does set default values in the WSDL but that still does not resolve the required field (MinOccurs=1) issue.

My research shows that .NET uses the data type to determine MinOccurs and, since a string is nullable, it always sets the MinOccurs=0.

I have tried numerous options but nothing seems to override that rule - are there any options?  Can I create a custom WSDL and force the web service to reference that WSDL somehow?
Bob Learned

May I ask about the bigger picture?  Are you using the web service with AJAX?  You might be able to use page methods to work with AJAX control toolkit extenders/components, rather than the web service...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

NO - this web service is being integrated via automation with a Java-based system.  That system shows those developers fields based on required/optional and they are not quite bright enough to enter data into any field marked as optional (MinOccurs=0).  I need to make these required fields without resorting to some ridiculous workaround such as creating custom objects.
Bob Learned

What arguments did you use with WSDL.EXE to generate the .wsdl?  

Did you override the default WSDL, with a custom one, using an attribute?

[WebServiceBinding(Name = "MyBinding", Location = "MyCustom.wsdl")]

So that correctly attached the WSDL - thank you!  

Now the problem is that my custom class is not being recognized.  I am being told that my class, which exits through a reference to my business layer, cannot be converted to the complex type identified in the WSDL.

I literally took the WSDL originally generated by .NET, changed the MinOccurs fields and tried using it and now these conversion errors are appearing...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Bob Learned

Can you show me the exact error when with the custom class, so that I can research the cause, and possible solution?

The current WSDL is found here: http://www.leadscoring.org/leadscorer.asmx?wsdl

I literally have a call:

[WebMethod(Description = "Pass in a Lead Id and obtain an XML file of the lead details, including score and status")]
    public Lead GetLeadDetail(string ServiceEmail, string Password, int LeadId)
        int personId = ValidateUser(ServiceEmail, Password);
        if (personId == 0)
            throw new SoapException("Unauthorized Access.", new System.Xml.XmlQualifiedName("LeadScore"));

        return businessLayer.GetLeadDetail(LeadId, personId) as Lead;


Where businessLayer is a class in a Class Library.  THat class library also contains a public, serializable, class with nothing but public properties called Lead.

When I reference the custom WSDL, I get and error unable to convert BusinessLayer.Lead into Lead.

When I mouse over Lead in the ASMX code behind, it is referencing the complex type from the WSDL.
Bob Learned

That sounds like a problem with known types.  With WCF, you can specify the known types.  I am not sure what your WSDL looks like...
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

HOw do you specify known types for things like strings in WCF?
Bob Learned

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thank you for your help