none
Simple WCF service to Get the O/p in form of xml RRS feed

  • Question

  • HI,

    I ma trying to create a small wcf service which takes an xml as an input like this(XSD provided)

      <?xml version="1.0" encoding="utf-16" ?> 
    - <xs:schema xmlns="http://LdsMessages.Schemas.DestSchema" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://LdsMessages.Schemas.DestSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    - <xs:element name="Dest">
    - <xs:complexType>
    - <xs:sequence>
    - <xs:element minOccurs="1" maxOccurs="unbounded" name="Destination">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="gfbc" type="xs:string" /> 
      <xs:element name="tyghvg" type="xs:string" /> 
    - <xs:element maxOccurs="unbounded" name="fc">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="Field" type="xs:string" /> 
      <xs:element name="hjnb" type="xs:string" /> 
    - <xs:element maxOccurs="unbounded" name="ghv">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="gv" type="xs:string" /> 
      <xs:element name="jh" type="xs:string" /> 
      <xs:element name="hjb" type="xs:string" /> 
      <xs:element name="vvnb" type="xs:string" /> 
      <xs:element name="gb" type="xs:string" /> 
      <xs:element name="gvh" type="xs:string" /> 
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:schema>


    Output will be like below

      <?xml version="1.0" encoding="utf-16" ?> 
    - <xs:schema xmlns="http://LdsMessages.Schemas.DestDestination" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://LdsMessages.Schemas.DestDestination" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    - <xs:element name="DestDestination">
    - <xs:complexType>
    - <xs:sequence>
    - <xs:element minOccurs="1" maxOccurs="unbounded" name="Destination">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="edw" type="xs:string" /> 
      <xs:element name="gftbf" type="xs:string" /> 
      <xs:element name="Field" type="xs:string" /> 
    - <xs:element minOccurs="1" maxOccurs="unbounded" name="ds">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="fd" type="xs:string" /> 
      <xs:element name="vd" type="xs:string" /> 
      <xs:element name="_x0020_c" type="xs:string" /> 
      <xs:element name="xcxz" type="xs:string" /> 
    - <xs:element minOccurs="1" maxOccurs="unbounded" name="cc">
    - <xs:complexType>
    - <xs:sequence>
      <xs:element name="vc" type="xs:string" /> 
      <xs:element name="ds" type="xs:string" /> 
      <xs:element name="bh" type="xs:string" /> 
      <xs:element name="cc" type="xs:string" /> 
      <xs:element name="cvcv" type="xs:string" /> 
      <xs:element name="_x0020_ccv" type="xs:string" /> 
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:schema>


    I have generated xsd classes for both these xsd's using xsd.exe added Data Contracts for these classes and My Serrvice code looks like below

      public DestDestination Post(Dest DestSchema)
            {
                DestDestination destination = new DestDestination();
                for (int i = 0; i < 5; i++)
    			{
                    destination.Destination[i].edw = "gyguyj";
                    destination.Destination[i].gftbf = "sxdas";
                    destination.Destination[i].Field = "cfsd";
                    for (int j = 0; j < 3; j++)
                    {
                        destination.Destination[i].ds[j].c = "fdvd";
                        destination.Destination[i].ds[j].fd = "sdc";
                        destination.Destination[i].ds[j].vd = "sdc";
                        destination.Destination[i].ds[j].xcxz = "sdc";
                        for (int k = 0; k < 3; k++)
                        {
                            destination.Destination[i].ds[j].cc[k].bh = "sd";
                            destination.Destination[i].ds[j].cc[k].cc = "Df";
                            destination.Destination[i].ds[j].cc[k].ccv = "fv";
                            destination.Destination[i].ds[j].cc[k].cvcv = "dfvd";
                            destination.Destination[i].ds[j].cc[k].ds = "df";
                            destination.Destination[i].ds[j].cc[k].vc = "sd";
    
                        }
    
                    }
    
    
    			}
                return destination;
                
            }

    when I am trying to run it by passing the Data I always Get null reference Exception when I am assigning the values.

    I am new to WCF services. Can you Please help me with this?

    Thanks,

    Sujith.

    Tuesday, October 25, 2016 10:21 AM

All replies

  • Why don't you send it as simple string data that's all XML is is primitive string data, then you can load it into an XML Document object on both sides and deal with it?
    Tuesday, October 25, 2016 8:53 PM
  • Hi Sujith,

    Have your issue been resolved? Based on your code, it seems you want to pass Dest and return DestDestination which is similar like your another thread Generated WCF Service from WSDL? Are they same issue? For setting DestDestination, I think there is no need to loop and you could try the simple code which I provide in another thread.

    If they are different issue, and has not been resolved, please feel free to let us know.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 28, 2016 6:04 AM