WCF客户端不接受服务的响应。由于EndpointDispatcher的AddressFilter不匹配,无法在接收方进行处理。

问题描述 投票:1回答:1

我是第一次写与wcf相关的东西,我按照文档等做了一切,但我不明白为什么我的客户端不想从服务中接收数据。而且,它只接受数据,从服务本身我不调用客户端中的方法,是不是意味着我有单向的wsHttpBinding?

任务如下:服务从客户端接收矩阵大小(5x5)和enum标识符,用于确定如何自己生成矩阵,在服务器上生成一个指定维度的随机矩阵,并返回 Matrix <double> 问题是,当矩阵返回给客户端时,我得到了以下消息,错误在调用GetMatrix方法的那一行。

当接收到HTTP响应到 http:/localhost:8080WCF_TRSPOService1。. 这可能是由于服务端点绑定不使用HTTP协议。

ServiceTrace说我,错误:

该消息与To 'http:/localhost:8080WCF_TRSPOService1mexmex。'不能在接收方处理,因为EndpointDispatcher的AddressFilter不匹配。检查发送方和接收方的EndpointAddresses是否一致。

看,如果我传递给客户端的不是矩阵,而是null,那么客户端就会接受。5x5矩阵则拒绝。同理。Vector <double>.我不明白是什么问题,谷歌搜索没有返回结果。给虽然指示在哪里看或我错在哪里?)

服务App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="WCF_TRSPO_Lib.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCF_TRSPO_Lib.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/WCF_TRSPO/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

客户端App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8080/WCF_TRSPO/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

服务接口

[ServiceContract]
    public interface IService1
    {       

        [OperationContract]
        ObjectObgortka GetMatrixData(int n, MatrixEnum Letter);

服务 数据源,数据集返回给客户

[DataContract]    
    public class ObjectObgortka
    {
        public ObjectObgortka()
        {
            _Matrix = null;
            _Vector = null;
        }

        public Matrix<double> _Matrix;

        public Vector<double> _Vector;        


        [DataMember]
        public Matrix<double> Matrix { get { return _Matrix; } set { _Matrix = value; } }
        [DataMember]
        public Vector<double> Vector { get { return _Vector; } set { _Vector = value; } }

服务项目

public class Service1 : IService1
    {        
        public ObjectObgortka GetMatrixData(int n, MatrixEnum Letter)
        {
            MatrixFactory matrixFactory = new MatrixFactory();

            ObjectObgortka obgortka = new ObjectObgortka();
            Console.WriteLine(n);
            obgortka.Matrix = matrixFactory.GetMatrix(Letter, n);
            //obgortka.Matrix = null;           
            return obgortka;                   
        }

和客户

 public static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            Service1Client client = new Service1Client();

            // Step 2: Call the service operations.
            // Call the Add service operation.
            Console.Write("N: ");
            int n = Convert.ToInt32(Console.ReadLine());
            var matrixA = client.GetMatrixData(n, MatrixEnum.A); //here var is ObjectObgortka type from Servic
            Matrix<double> MatrixA = matrixA.Matrix;
c# wcf wcf-binding wcfserviceclient
1个回答
0
投票

MathNet.Numerics.LinearAlgebra.Double.DenseMatrix'的数据合约名为'DenseMatrix:schemas.datacontract.org200407...'是不希望的。如果使用DataContractSerializer,请考虑使用DataContractResolver,或者将任何静态不已知的类型添加到已知类型列表中--例如,通过使用KnownTypeAttribute属性或将它们添加到传递给序列化器的已知类型列表中。

该错误通常表明服务器端和客户端不知道如何序列化和反序列化复杂的数据类型。由于 Maxtrix<double>, Vector<double> 请考虑用DataContract属性来装饰复杂类型,并使用Known type来预先指定在序列化过程中应考虑的类型。

[DataContract]
[KnownType(typeof(CircleType))]
[KnownType(typeof(TriangleType))]
public class CompanyLogo2
{
    [DataMember]
    private Shape ShapeOfLogo;
    [DataMember]
    private int ColorOfLogo;
}
[DataContract]
public class Shape { }

[DataContract(Name = "Circle")]
public class CircleType : Shape { }

[DataContract(Name = "Triangle")]
public class TriangleType : Shape { }

详细内容请参考 https:/docs.microsoft.comen-usdotnetframeworkwcffeature-detailsusing-data-contracts。 https:/docs.microsoft.comen-usdotnetframeworkwcffeature-detailsdata-contract known-types。 如果有什么需要我帮忙的,请随时告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.