NullReferenceException when generating web service code

Jun 14, 2010 at 10:46 PM

Devs,

I'm trying to generate the web service code from a very simple schema but I get a "NullReferenceException" when trying to generate the web service code.

Here's the schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema
  xmlns="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0"
  elementFormDefault="qualified"
  targetNamespace="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0"
  id="MyServiceMessages"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="MyOperationRequest">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Param1" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="MyOperationResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Param2" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

This generates the following WSDL:

<!--WSDL generated by thinktecture WSCF; version 1.0.9.0-->
<!--Monday, 14-06-2010 - 11:38 PM-->
<definitions xmlns:tns="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MyService" targetNamespace="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <types>
    <xsd:schema>
      <xsd:import schemaLocation="MyServiceMessages-v1.0.xsd" namespace="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0" />
    </xsd:schema>
  </types>
  <message name="myOperationIn">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="tns:MyOperationRequest" />
  </message>
  <message name="myOperationOut">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="tns:MyOperationResponse" />
  </message>
  <portType name="MyServiceInterface">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <operation name="MyOperation">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
      <input message="tns:myOperationIn" />
      <output message="tns:myOperationOut" />
    </operation>
  </portType>
  <binding name="BasicHttpBinding_MyServiceInterface" type="tns:MyServiceInterface">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="MyOperation">
      <soap:operation soapAction="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0:myOperationIn" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
  </binding>
</definitions>

If I try to generate the web service code from this I get the NullReferenceException.

I am using the latest version available for download.

Any ideas? I've tried all combinations of options.

Thanks,

Callum

 

Developer
Jun 15, 2010 at 9:02 AM

Hi Callum,

I tested the XSD and WSDL you provided but did not get the NullReferenceException for client-side proxy or service-side stub.

Are you getting the NullReferenceException in a message box? If so, can you please use Ctrl-C to copy the full error message with stack trace into the clipboard and then post it here.

Cheers,

Alex.

Jun 15, 2010 at 10:52 PM

Alex,

Thanks for the response. Yes, it is in a message box. Here is the stack trace:

---------------------------
CodeGeneration
---------------------------
System.NullReferenceException: Object reference not set to an instance of an object.

   at System.ServiceModel.Configuration.ServiceEndpointElementCollection.GetElementKey(ConfigurationElement element)

   at System.ServiceModel.Configuration.ServiceModelEnhancedConfigurationElementCollection`1.BaseAdd(ConfigurationElement element)

   at System.ServiceModel.Configuration.ServiceModelConfigurationElementCollection`1.Add(ConfigurationElementType element)

   at Thinktecture.Tools.Web.Services.CodeGeneration.ConfigurationDecorator.GenerateServiceConfiguration()

   at Thinktecture.Tools.Web.Services.CodeGeneration.ConfigurationDecorator.Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)

   at Thinktecture.Tools.Web.Services.CodeGeneration.CodeDecorators.ApplyDecorations(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)

   at Thinktecture.Tools.Web.Services.CodeGeneration.CodeGenerator.GenerateCode(CodeGenerationOptions options)

   at Thinktecture.Tools.Web.Services.ContractFirst.Connect.ProcessCodeGenerationRequestCore(String wsdlFile)
---------------------------
OK  
---------------------------

If I can provide more info, let me know.

Thanks,

Callum

Developer
Jun 16, 2010 at 1:08 PM

Hi Callum,

Does your WSDL have a <service/> element? I think you might be missing the <soap:address/>.

<service name="MyServicePort">
  <port name="MyServicePort" binding="tns:BasicHttpBinding_MyServiceInterface">
    <soap:address location="http://localhost/MyService" />
  </port>
</service>
If the <port/> element is empty you will get that exception.

Cheers,

Alex.

Jun 16, 2010 at 3:18 PM
I have run through the WSCF.blue wizard again. This time I generated the WSDL from the schema in the first post above. I checked the "Generate <service> element" option and I get this WSDL:
<!--WSDL generated by thinktecture WSCF; version 1.0.9.0-->
<!--Wednesday, 16-06-2010 - 04:10 PM-->
<definitions xmlns:tns="http://schemas.acme.com/MyApp/MyService/v1.0" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:import0="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MyService" targetNamespace="http://schemas.acme.com/MyApp/MyService/v1.0" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <types>
    <xsd:schema>
      <xsd:import schemaLocation="MyServiceMessages-v1.0.xsd" namespace="http://schemas.acme.com/MyApp/MyServiceMessages/v1.0" />
    </xsd:schema>
  </types>
  <message name="myOperationIn">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="import0:MyOperationRequest" />
  </message>
  <message name="myOperationOut">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="import0:MyOperationResponse" />
  </message>
  <portType name="MyServiceInterface">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <operation name="MyOperation">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
      <input message="tns:myOperationIn" />
      <output message="tns:myOperationOut" />
    </operation>
  </portType>
  <binding name="BasicHttpBinding_MyServiceInterface" type="tns:MyServiceInterface">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="MyOperation">
      <soap:operation soapAction="http://schemas.acme.com/MyApp/MyService/v1.0:myOperationIn" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
  </binding>
  <service name="MyServicePort">
    <port name="MyServicePort" binding="tns:BasicHttpBinding_MyServiceInterface">
      <soap:address location="http://localhost/MyService" />
    </port>
  </service>
</definitions>

This WSDL does have the "port" element but I get the exact same exception as shown in the previous post.

I am a bit confused as I am using WSCF.blue end to end. I have a basic schema from which WSCF.blue has no problems infering the operations. From this I generate the WSDL and then try to generate the service from that but I get the error. As WSCF.blue is generating the WSDL I am a bit surprised.

Any more ideas?

Callum

Developer
Jun 21, 2010 at 1:35 PM

Hi Callum,

Are you able to send me a copy of the project? You can contact me through my profile page. I will reply to the message so you can email the project.

http://www.codeplex.com/site/users/view/alexmeyergleaves

Cheers,

Alex.

Nov 17, 2010 at 10:31 AM

Was a solution for this found? I am having the same issue with the latest version.

Thanks,

Andrew

Nov 17, 2010 at 9:10 PM

Andrew,

The issue for me was environmental I think. I experienced the problem on a Windows Server 2003 machine but trying on another machine (which was Windows Server 2008 R2) the problem disappeared.

We never found the root cause, I was happy to use the other machine.

Callum