我是第一次写wcf相关的东西,我都是按照文档做的等等,但是我不明白为什么我的客户不想从服务接收数据。而且,它只接受数据,从服务本身我不调用客户端中的方法,是不是意味着我有单向wsHttpBinding?
任务如下:服务从客户端接收矩阵大小(5x5)和枚举标识符,用于确定如何自己生成矩阵,在服务器上生成指定维度的随机矩阵并返回Matrix <double>
给客户端。然后这个矩阵将再次被转移到服务中进行操作。问题是当矩阵返回给客户端时,我得到以下消息,并且错误在调用GetMatrix方法的行中。
接收对http://localhost:8080/WCF_TRSPO/Service1/的 HTTP 响应时出错。这可能是由于服务端点绑定未使用 HTTP 协议。
ServiceTrace 告诉我这个错误:
由于 EndpointDispatcher 中的 AddressFilter 不匹配,接收方无法处理带有 To ' http://localhost:8080/WCF_TRSPO/Service1/mex/mex '的消息。检查发送方和接收方的 EndpointAddresses 是否一致。
看,如果我传递给客户端的不是矩阵,而是 null,那么客户端会接受它。5x5 矩阵拒绝。同样,Vector <double>
。我不明白问题是什么,谷歌搜索没有返回结果。给出指示在哪里看或我错在哪里?)
服务应用程序.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;