Usher
Usher

Reputation: 2146

stuck up to call the WCF object

This is quite embarrassing ,tried to find the solution by myself but real lack of knowledge i couldn't able to ,so am posting my question here.

my wcf service return this value when i call my service

   <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetProcessLocationsResponse xmlns="http://tempuri.org/">
         <GetProcessLocationsResult >
            <a:ProcessLocationData>
               <a:Id>1</a:Id>
               <a:Name>IL</a:Name>
            </a:ProcessLocationData>
            <a:ProcessLocationData>
               <a:Id>2</a:Id>
               <a:Name>MD</a:Name>
            </a:ProcessLocationData>
            <a:ProcessLocationData>
               <a:Id>3</a:Id>
               <a:Name>NY</a:Name>
            </a:ProcessLocationData>
             </GetProcessLocationsResult>
      </GetProcessLocationsResponse>
   </s:Body>
</s:Envelope>

in my service class i wrote this method

 public Array GetProcessLocations()
    {
        return this.GetSoapServiceClient().GetProcessLocations().ToArray();
    }

    public List<ProcessLocationData> GetProcessLocationsOnlyName()
    {
        return this.GetSoapServiceClient().GetProcessLocations().ToList();
    }

i call this service in my xyz.class like below

 Array GetProcLocation=  new GatewayService().GetProcessLocations();

this return whole object like ID and Name

but i was trying to get only the name by calling the "GetProcessLocationsOnlyName" method

i was trying to do like below

array ProcName= ProcessLocationData.Name

should return all the name in the service like (IL,MD,NY) in the array but i couldn't able to see ProcessLocationData at all.

In another way i was trying to split the array(GetProcLocation) and get only the name and add in to new array ? is that make sense ?

Please some one guide me in to right path.thanks in advance.

Upvotes: 0

Views: 180

Answers (1)

Andrei Gavrila
Andrei Gavrila

Reputation: 863

I am a little confused about your question. I do understand that you want to have 2 service methods, both of them returning an array of ProcessLocationData, one returning the list with id and name (GetProcessLocations) and one returning an array of ProcessLocationData with name only (GetProcessLocationsOnlyName). And your problem is that the client proxy doesn't contain the GetProcessLocationsOnlyName method.

You should make sure that both methods are annotated with OperationContract, otherwise they won't be exposed by your service. You should have this attribute in either your service interface or in service directly. You can see that your service exposes both methods in either wsdl or using the WCF Test Client.

And then you must make sure your client proxy is up to date.

  • If your client proxy is was generated using visual studio, you should try to update your service reference
  • If your client proxy is generated using svcutil you must regenerate it manually

Related to your comment, if you want to return only the name field you have the following options.

  • you can use the same DataContract, that means returning a list of ProcessLocationData and returning an empty Id for each object
  • you can create a new DataContract that has only one property, Name, and return a list of these objects

My advice is to use the same DataContract and to load only the needed data in the data access method. For example, make a new method GetProcessLocationsName(), that will create your list of ProcessLocationData with only their Name loaded.

Upvotes: 2

Related Questions