开发者

Error in consuming WCF service in ClassLibrary

I am consuming a WCF in a classLibrary by adding a web reference of the WCF service.

All the classes of service are showing, their is no build error.

But when calling the method of service, getting the below mentioned error:-

And I am passing a object in the method which contains the xml.

But when I am making a proxy class by using svcutil.exe ,then call the method of service with the same object having same xml no error is coming, it is working fine.

_**It means that in classLibrary we can consume a WCF service only by creating a proxy not by adding the web reference of the WCF service.

Is the above stat开发者_如何学Pythonement is correct or not?

If not then please provide a solution for it.**_

**Error:

System.InvalidOperationException: There is an error in XML document (1, 528). ---> System.InvalidOperationException: Instance validation error: '' is not a valid value for PropertySubType.
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read29_PropertySubType(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read30_Hotel(Boolean isNullable, Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read31_SearchResult(Boolean isNullable, Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read100_SearchHotelsResponse()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer8.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at ClassLibTestTouricoWCFinCsharp.com.touricoholidays.demo2.HotelFlow.SearchHotels(SearchRequest request) in C:\Documents and Settings\Prakash.singh\My Documents\Visual Studio 2005\Projects\ClassLibTestTouricoWCFinCsharp\ClassLibTestTouricoWCFinCsharp\Web References\com.touricoholidays.demo2\Reference.cs:line 132
   at ClassLibTestTouricoWCFinCsharp.Class1.test() in C:\Documents and Settings\Prakash.singh\My Documents\Visual Studio 2005\Projects\ClassLibTestTouricoWCFinCsharp\ClassLibTestTouricoWCFinCsharp\Class1.cs:line 78**


You're basically seeing the difference between a Service Reference and a Web Reference. What it sounds like is that the WCF service you are consuming is not compatible with adding a web reference, and you should instead use the service reference.

Having said that, it's much cleaner to not use either, and instead use a ChannelFactory or create your own proxy by deriving from ClientBase. Here is an example of using a ChannelFactory.

ChannelFactory<IContract> factory = new ChannelFactory<IContract>("BindingConfigName");
IContract channel = factory.CreateChannel();

channel.YourOperation();

((ICommunicationObject)channel).Close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜