.NET Framework Bookmark and Share   
 index > ASMX Web Services and XML Serialization > Referencing a web service is cumbersome
 

Referencing a web service is cumbersome

I am referencing a web service and implementing all the code that populates all the objects which will in term be serialized however it struck me as how much time its taking.

I look at the xml structure and think if I used XElement to build that up and send it it would take 10 minutes. But all these classes that are generated when referencing the web service take a huge amount of time to populate.

Is there anyway of just building up the xml manually and sending that to the web service, or does the web service have to specifically accept a stream of xml?

  • Changed TypeTheLearner Thursday, September 10, 2009 8:18 AMThere is no definitive answer
  •  
TheLearner
If the web service is designed to take objects, then you'll have to send objects, unless you want to do everything "by hand".

Have you done profiling to determine what's taking the time? You might find that XML is no faster.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
How do I send it "by hand".

The part that is taking the time is the development not the web service.
TheLearner
Can you be more specific about the performance problem?

John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
There is no performance problem.

Development time is the problem. The time it takes for a developer to write code that populates these objects is taking a long time.

If a developer just had to build some xml using XElement it would take less development time.

I am taking about man hours here.
TheLearner
Perhaps you can give an example of the code you're using to populate an object. I can't offhand think why it would take longer to populate an object than to create XML.

John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
In order to build this simple piece of XML:

<OTA_HotelAvailRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="1">
<AvailRequestSegments>
<AvailRequestSegment>
<StayDateRange Start="2008-10-12" Start="2008-10-19" />
<RoomStayCandidates>
<RoomStayCandidate>
<GuestCounts>
<GuestCount AgeQualifyingCode="10" Count="2" />
<GuestCount AgeQualifyingCode="7" />
</GuestCounts>
</RoomStayCandidate>
<RoomStayCandidate>
<GuestCounts>
<GuestCount AgeQualifyingCode="10" Count="2" />
<GuestCount AgeQualifyingCode="8" Age="10" />
</GuestCounts>
</RoomStayCandidate>
</RoomStayCandidates>
<HotelSearchCriteria>
<Criterion>
<HotelRef ChainCode="H4U" HotelCode="6568" />
</Criterion>
<Criterion>
<HotelRef ChainCode="H4U" HotelCode="14" />
</Criterion>
January 7, 2009 Page 21
Functional Requirements Document
Hotels4U.com Webservices Developers Guide
</HotelSearchCriteria>
</AvailRequestSegment>
</AvailRequestSegments>
</OTA_HotelAvailRQ>


I need to write all this code:

public bool IsHotelAvailable(IOffer offer)
{
_offer = offer as AccommodationOffer;

sendOTAHotelAvailRequest sentAvailabilityRequest = new sendOTAHotelAvailRequest
{
authentication = GetAuthentication(),
OTA_HotelAvailRQ = GetAvailabilityRequest(),
};

sendOTAHotelAvailResponse sentAvailabilityResponse = _externalService.sendOTAHotelAvail(sentAvailabilityRequest);

return true;
}

private OTA_HotelAvailRQ GetAvailabilityRequest()
{
OTA_HotelAvailRQ result = new OTA_HotelAvailRQ
{
AvailRequestSegments = GetAvailRequestSegments()
};

return result;
}

private AvailRequestSegmentsType GetAvailRequestSegments()
{
AvailRequestSegmentsType result = new AvailRequestSegmentsType
{
AvailRequestSegment = GetAvailRequestSegment()
};

return result;
}

private AvailRequestSegmentsTypeAvailRequestSegment[] GetAvailRequestSegment()
{
List<AvailRequestSegmentsTypeAvailRequestSegment> result =
new List<AvailRequestSegmentsTypeAvailRequestSegment>();

AvailRequestSegmentsTypeAvailRequestSegment segment = new AvailRequestSegmentsTypeAvailRequestSegment
{
StayDateRange = GetStayDateRange(),
RoomStayCandidates = GetRoomStayCandidates(),
HotelSearchCriteria = GetHotelSearchCriteria()
};

result.Add(segment);
return result.ToArray();
}

private HotelSearchCriterionType[] GetHotelSearchCriteria()
{
List<HotelSearchCriterionType> result = new List<HotelSearchCriterionType>();

HotelSearchCriterionType type = new HotelSearchCriterionType
{
HotelRef = GetHotelRef()
};

result.Add(type);
return result.ToArray();
}

private ItemSearchCriterionTypeHotelRef GetHotelRef()
{
throw new NotImplementedException();
}

private RoomStayCandidateType[] GetRoomStayCandidates()
{
List<RoomStayCandidateType> result = new List<RoomStayCandidateType>();

RoomStayCandidateType candidate = new RoomStayCandidateType
{
GuestCounts = GetGuestCounts()
};

result.Add(candidate);
return result.ToArray();
}

private GuestCountType GetGuestCounts()
{
GuestCountType result = new GuestCountType()
{
GuestCount = GetGuestCount()
};

return result;
}

private GuestCountTypeGuestCount[] GetGuestCount()
{
List<GuestCountTypeGuestCount> result = new List<GuestCountTypeGuestCount>();

foreach (var passenger in _offer.Passengers)
{
GuestCountTypeGuestCount guestCount = new GuestCountTypeGuestCount
{
AgeQualifyingCode = GetAgeQualifyingCode(passenger)
};

result.Add(guestCount);
}

return result.ToArray();
}

private string GetAgeQualifyingCode(IPassenger passenger)
{
switch (passenger.Type)
{
case PassengerType.Adult:
return "10";
case PassengerType.Child:
return "8";
case PassengerType.Infant:
return "7";
default:
throw new NotSupportedException("The passenger type is not supported");
}
}

private DateTimeSpanType GetStayDateRange()
{
DateTimeSpanType result = new DateTimeSpanType
{
Start = _offer.Accommodation.CheckInDateTime.ToString("yyyy-MM-dd"),
Duration = string.Format("P{0}N", TapiCoreHelper.OfferDuration(_offer)),
End = _offer.Accommodation.CheckOutDateTime.ToString("yyyy-MM-dd")
};

return result;
}
TheLearner
Great, but how would that be faster if you built the XML?

John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
One method:

XNamespace ns = "http://www.opentravel.org/OTA/2003/05";
XElement xml = new XElement(ns + "OTA_HotelAvailRQ",
new XAttribute("xmlns", ns),
new XAttribute("Version", "1"),
new XElement(ns + "AvailRequestSegments",
new XElement(ns + "AvailRequestSegment",
new XElement(ns + "StayDateRange",
new XAttribute("Start", "2008-10-12")
),
new XElement(ns + "RoomStayCandidates",
new XElement(ns + "RoomStayCandidate",
new XElement(ns + "GuestCounts",
new XElement(ns + "GuestCount",
new XAttribute("AgeQualifyingCode", "10"),
new XAttribute("Count", "2")
),
new XElement(ns + "GuestCount",
new XAttribute("AgeQualifyingCode", "7")
)
)
),
new XElement(ns + "RoomStayCandidate",
new XElement(ns + "GuestCounts",
new XElement(ns + "GuestCount",
new XAttribute("AgeQualifyingCode", "10"),
new XAttribute("Count", "2")
),
new XElement(ns + "GuestCount",
new XAttribute("AgeQualifyingCode", "8"),
new XAttribute("Age", "10")
)
)
)
),
new XElement(ns + "HotelSearchCriteria",
new XElement(ns + "Criterion",
new XElement(ns + "HotelRef",
new XAttribute("ChainCode", "H4U"),
new XAttribute("HotelCode", "6568")
)
),
new XElement(ns + "Criterion",
new XElement(ns + "HotelRef",
new XAttribute("ChainCode", "H4U"),
new XAttribute("HotelCode", "14")
)
),
"\n" +
"January 7, 2009 Page 21\n" +
"Functional Requirements Document\n" +
"Hotels4U.com Webservices Developers Guide\n"
)
)
)
);

TheLearner
BTW, is there anyway of taking that OTA_HotelAvailRQ object and seeing it in XML form?

The reason I ask is the web service is thrown an exception but obviously I can't determine what is wrong on my side. It's throwing an object reference not set exception.
TheLearner
When you add the code to fetch, for example, "H4U", I think you'll find the two to be roughly equivalent. Your XElement version is simpler because you're not fetching the data values in it.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
You can explicitly XML Serialize it, or you can look at the data on the wire (which is probably better). See Ways to See SOAP Traffic for some pointers.

John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
Cheers thanks I serialized it and it worked.
TheLearner
Getting back to my original question - baring in mind I am very new to web services - is this really all worthwhile? I mean I even had to create a method to create an array of strings just to set the surname of a person!?!?
TheLearner
And now you have your method for creating an array of strings, and can reuse it next time.

John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
John Saunders
True I guess - I will stop bugging you now :) but I just have to say after working with LINQ and only now really consuming a web service I feel like I have taken a huge step back. But I guess thats just the nature of the web services.
TheLearner

You can use google to search for other answers

Custom Search

More Threads

• Retrieving detailed error message, when parsing fails.
• Does WseWsdl3.exe support a parameter file?
• Return DataTable or DataSet without schema
• VS2005 - I cannot add a new web form, master page, web service, etc - object reference...
• How to resolve Warning: conflict between files (imported type)
• Datasets the Only way or Visual Studio 2008 broken
• Axis web service "multiRef" issue
• access values from webform1 to webform2
• Newbie webserver question
• Using the webservice on a client computer