在WCF

时间:2019-03-18 11:11:02

标签: c# .net wcf

我已经编写了一个核心Web服务。该Web服务处理所有计算,数据操作等。

此Web服务与我的微服务在同一解决方案中。

我的微服务应与我的核心Web服务通信,并返回其从核心Web服务接收的对象。问题在于它不起作用,因为当我启动解决方案时,它无法转换数据协定的引用对象。

WCF测试客户端上的异常:

  

错误CS0644:“ System.ComponentModel.PropertyChangedEventHandler”   无法从特殊类“ System.MulticastDelegate”派生

当我添加COREservice作为参考时,它会自动生成实现INotifyPropertyChanged的类。

现在,我当然可以编写广泛的转换器,将将从核心Web服务器接收的所有对象转换为具有相同名称但在本地定义的对象,这只会花费很多工作,而且我怀疑没有任何工作其他更快/更优雅的解决方法。


IService:

    [OperationContractAttribute(AsyncPattern = true)]
    IAsyncResult BeginOperation(string Salesperson, decimal Timestamp, AsyncCallback asyncCallback, object state);
    CoreWebservice.ReturnObj EndOperation (IAsyncResult result);

服务:

public CoreWebservice.ReturnObj Operation(string Salesperson = null, decimal? Timestamp = null, OperationContext opContext = null)
{
    CoreWebservice.ReturnObj result = CoreService.Operation(Salesperson, Timestamp ?? default(decimal));

    return result;
}

端点:

<client>
  <endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_M3ApiCalls"
    contract="COREservice.ApiCalls" name="BasicHttpBinding_M3ApiCalls" />
</client>

所有类或“ Resultobjects”都以相同的方式编写(与结果和一个recordresult类配对)

[Serializable()]
[DataContract]
[XmlSerializerFormat()]
[XmlRoot(ElementName = "CRS100MI_List",DataType = "System.Xml.XmlElement",Namespace = "http://www.the.namespace/of/company")]
public class CRS100MI_ListResult
{
    [DataMember]
    [System.Xml.Serialization.XmlElement(Order = 0)]
    public string Result = "";

    //etc....

    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Order = 3)]
    public List<CRS100MI_ListRecordResult> Record = new List<CRS100MI_ListRecordResult>();



    public CRS100MI_ListResult Parse(List<Dictionary<string, string>> list)
    {
        //parse a list of dictionaries to fill the fields of the 
        //recordresult, and return the entire object populated with records.

        return this;
    }
}

[Serializable()]
[DataContract(Namespace = "http://www.rexel.nl/M3/ApiCalls")]
[XmlSerializerFormat()]
[XmlRoot(ElementName = "CRS100MI_ListRecord", DataType = "System.Xml.XmlElement", Namespace = "http://www.the.namespace/of/company")]
public class CRS100MI_ListRecordResult
{


    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public string Result               { get; set; }

    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public string ErrorMessage         { get; set; }

    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Order = 2)]
    public List<string> Messages           { get; set; }

    //etc...

}

所以,总结一下:

    MICROservice的服务参考引用了
  1. COREservice
  2. COREservice返回一个对象,该对象将由MICROservice返回
  3. MICROservice依赖于COREservice
  4. 抛出错误CS0644,因为它可能无法从COREservice派生完整类

    通过引用COREservice也许这可以解决吗?还是我可能忽略了另一种解决方案?

0 个答案:

没有答案