简体   繁体   English

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

[英]WCF Client does not accept response from service. Cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher

I am writing for the first time something related to wcf, I did everything according to the documentation, etc., but I do not understand why my client does not want to receive data from the service.我第一次写与wcf相关的东西,我根据文档等做了一切,但我不明白为什么我的客户不想从服务接收数据。 Moreover, it only accepts data, from the service itself I do not call methods in the client, does it mean that I have one-way wsHttpBinding?而且,它只接受数据,从服务本身我不调用客户端中的方法,是不是意味着我有单向wsHttpBinding?

The task is as follows: the service receives from the client the matrix size (5x5) and enum identifier for determining how to generate the matrix itself, a random matrix of the specified dimension is generated on the server and returns Matrix <double> to the client.任务如下:服务从客户端接收矩阵大小(5x5)和枚举标识符,用于确定如何自己生成矩阵,在服务器上生成一个指定维度的随机矩阵并将Matrix <double>返回给客户。 Then this matrix will again be transferred to the service for operations with it.然后这个矩阵将再次被转移到服务中进行操作。 The problem is that I get the following message when the matrix is returned to the client and the error is in the line where the GetMatrix method is called.问题是当矩阵返回到客户端时我收到以下消息,并且错误出现在调用 GetMatrix 方法的行中。

An error occurred while receiving the HTTP response to http://localhost:8080/WCF_TRSPO/Service1/ .接收对http://localhost:8080/WCF_TRSPO/Service1/的 HTTP 响应时出错。 This could be due to the service endpoint binding not using the HTTP protocol.这可能是由于服务端点绑定未使用 HTTP 协议。

ServiceTrace says me that error: ServiceTrace 告诉我这个错误:

The message with To ' http://localhost:8080/WCF_TRSPO/Service1/mex/mex ' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.由于 EndpointDispatcher 中的 AddressFilter 不匹配,接收方无法处理带有 To ' http://localhost:8080/WCF_TRSPO/Service1/mex/mex '的消息。 Check that the sender and receiver's EndpointAddresses agree.检查发送方和接收方的 EndpointAddresses 是否一致。

Look, if I pass to the client not the matrix, but null, then the client accepts it.看,如果我传递给客户端的不是矩阵,而是 null,那么客户端会接受它。 The 5x5 matrix refuses. 5x5 矩阵拒绝。 Similarly, Vector <double> .同样, Vector <double> I don't understand what the problem is, Google search did not return results.我不明白问题是什么,谷歌搜索没有返回结果。 Give though directions where to look or where I was wrong?)给出指示在哪里看或我错在哪里?)

Service App.config服务应用程序.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>

Client App.config客户端 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>

Service interface服务接口

[ServiceContract]
    public interface IService1
    {       

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

Service Data source where data set return to client数据集返回客户端的服务数据源

[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; } }

Service服务

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;                   
        }

and Client和客户

 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;

MathNet.Numerics.LinearAlgebra.Double.DenseMatrix' with data contract name 'DenseMatrix:schemas.datacontract.org/2004/07/…' is not expected.数据合同名称为“DenseMatrix:schemas.datacontract.org/2004/07/…”的 MathNet.Numerics.LinearAlgebra.Double.DenseMatrix' 不是预期的。 Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer如果您使用 DataContractSerializer 或将任何静态未知的类型添加到已知类型列表中,请考虑使用 DataContractResolver - 例如,通过使用 KnownTypeAttribute 属性或将它们添加到传递给序列化程序的已知类型列表中

The error typically indicates that the server-side and the client-side failed to know how to serialize and deserialize the complex data type.该错误通常表明服务器端和客户端不知道如何序列化和反序列化复杂数据类型。
Since the Maxtrix<double> , Vector<double> cannot be recognized by WCF, we have to tell him what the data type structure is and how to serialize it into XML(the payload in HTTP).由于Maxtrix<double>Vector<double> ,我们必须告诉他数据类型结构是什么以及如何将其序列化为 XML(HTTP 中的有效负载)。 Please consider to decorate the complex type with DataContract attribute and use Known type to specify the types that should be included for consideration during serialization in advance.请考虑使用 DataContract 属性来装饰复杂类型,并使用 Known 类型来指定在序列化过程中提前考虑的类型。

[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 { }

For more details,更多细节,
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-contract-known-types https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-contract-known-types
Feel free to let me know if there is anything I can help with.如果有什么我可以帮忙的,请随时告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误由于EndpointDispatcher的AddressFilter不匹配,带有To&#39;&#39;的消息无法在接收方处理 - Error The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher "由于 EndpointDispatcher 的 AddressFilter 不匹配,接收方无法处理带有 To &#39;...&#39; 的消息" - The message with To '...' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher 由于EndpointDispatcher的ContractFilter不匹配,因此无法在接收方处理带有动作&#39;&#39;的消息。 - The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. 由于EndpointDispatcher的ContractFilter不匹配,带有Action的消息无法在接收方处理 - The message with Action cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher WCF配置AddressFilter不匹配 - WCF Configuration AddressFilter mismatch WCF - AddressFilter不匹配 - WCF - AddressFilter mismatch 从Windows服务中托管WCF服务。 无法连接 - Hosting a WCF service from within a Windows Service. cannot be reached WCF- ContractFilter在EndpointDispatcher上不匹配 - WCF- ContractFilter mismatch at the EndpointDispatcher WCF ContractFilter 在 EndpointDispatcher 错误处不匹配 - WCF ContractFilter mismatch at the EndpointDispatcher error 从WCF服务返回我的对象​​。 - Return my object from WCF service.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM