gpt4 book ai didi

wcf - 为什么我从 WSDL 调用返回 System.InvalidOperationException 而不是从对另一个服务的同一调用中返回?

转载 作者:行者123 更新时间:2023-12-03 20:49:45 33 4
gpt4 key购买 nike

我创建了服务来获取各种客户的国家详细信息,但是在托管服务时我得到了这个异常。我正在使用基本的 http 绑定(bind)。

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a
WSDL export extension:
System.ServiceModel.Description.DataContractSerializerOperationBehavior
contract: http://tempuri.org/:IReferenceDataService ---->
System.Runtime.Serialization.InvalidDataContractException:
Type 'Pariwaar.BusinessObject.CountryBO' cannot be serialized.
Consider marking it with the DataContractAttribute attribute,
and marking all of its members you want serialized with the
DataMemberAttribute attribute. See the Microsoft .NET Framework
documentation for other supported types.
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.GetDataContract(RuntimeTypeHandle typeHandle, Type type, SerializationMode mode)
at System.Runtime.Serialization.DataContractSet.GetDataContract(Type clrType)
at System.Runtime.Serialization.DataContractSet.GetItemTypeDataContract(CollectionDataContract collectionContract)
at System.Runtime.Serialization.DataContractSet.AddCollectionDataContract(CollectionDataContract collectionDataContract)
at System.Runtime.Serialization.DataContractSet.Add(XmlQualifiedName name, DataContract dataContract)
at System.Runtime.Serialization.DataContractSet.Add(Type type)
at System.Runtime.Serialization.XsdDataContractExporter.Export(Type type)
at System.ServiceModel.Description.MessageContractExporter.ExportType(Type type, String partName, String operationName, XmlSchemaType& xsdType)
at System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32 messageIndex, Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32 messageIndex, Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext)
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
--- End of inner ExceptionDetail stack trace ---
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
at System.ServiceModel.Description.WsdlExporter.CallExportContract(WsdlContractConversionContext contractContext)
at System.ServiceModel.Description.WsdlExporter.ExportContract(ContractDescription contract)
at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName)
at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
at SyncInvokeGet(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

我有 businessobject[datamember]在另一个项目中。我在这里提到了它的dll。

你可以查看我的类(class)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Pariwaar.BusinessObject;
using Pariwaar.DataAccessLayer;

namespace Pariwaar.WCFServices.SVC
{
// NOTE: If you change the class name "ReferenceDataService" here, you must also update the reference to "ReferenceDataService" in Web.config.
public class ReferenceDataService : IReferenceDataService
{
ReferenceData objDAL = new ReferenceData();

public List<CountryBO> GetCountry()
{ return objDAL.GetCountry(); }

public List<StateBO> GetState(int CountryId)
{ return objDAL.GetState(CountryId); }

public List<CityBO> GetCity(int StateId)
{ return objDAL.GetCity(StateId); }
}
}

为什么这在另一个 WCF 服务上工作正常,但在另一个服务上给我一个错误?

最佳答案

好吧,错误很明显:

System.Runtime.Serialization.InvalidDataContractException: Type 'Pariwaar.BusinessObject.CountryBO' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.



您显然在使用数据类型 Pariwaar.BusinessObject.CountryBO作为 WCF 服务方法之一的参数或返回值,但该类没有 [DataContract]属性就可以了。

请参阅 Using Data Contracts 上的 MSDN 文档了解数据协定以及如何使您的对象可被 WCF 使用。看到这个 blog post - WCF Basics: Data Contracts对于同一主题的另一种观点。

所有复杂类型(例如类)都应该用 [DataContract] 标记,所有要包含在 WCF 消息中的字段都应该用 [DataMember] 标记:
[DataContract]
class Pariwaar.BusinessObject.CountryBO
{
[DataMember]
string CountryName { get; set; }

[DataMember]
string CountryCurrency { get; set; }

[DataMember]
string CountryISOCode { get; set; }

........
}

马克

关于wcf - 为什么我从 WSDL 调用返回 System.InvalidOperationException 而不是从对另一个服务的同一调用中返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1914452/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com