Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以编程方式连接到托管在IIS中的WCF服务_C#_Asp.net Mvc_Wcf_Wcf Binding - Fatal编程技术网

C# 如何以编程方式连接到托管在IIS中的WCF服务

C# 如何以编程方式连接到托管在IIS中的WCF服务,c#,asp.net-mvc,wcf,wcf-binding,C#,Asp.net Mvc,Wcf,Wcf Binding,托管在IIS中的我的WCF服务的绑定和客户端端点如下所示 <bindings> <customBinding> <binding name="notSecureBinding"> <binaryMessageEncoding /> <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize=

托管在IIS中的我的WCF服务的绑定和客户端端点如下所示

<bindings>
    <customBinding>
          <binding name="notSecureBinding">
              <binaryMessageEncoding />
              <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
          </binding>
          <binding name="SecureBinding">
              <binaryMessageEncoding />
              <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
          </binding>
      </customBinding>
  </bindings>



<client>
      <endpoint address="http://ServerName.myDomain.org/ADSearcher/Service1.svc"
                binding="customBinding"
                bindingConfiguration="notSecureBinding"
                contract="GetData.GetData"
                name="notSecureBinding" />

      <endpoint address="https://ServerName.myDomain.org/ADSearcher/Service1.svc"
                binding="customBinding"
                bindingConfiguration="SecureBinding"
                contract="GetData.GetData"
                name="SecureBinding" />
  </client>

现在我要做的是连接到这个服务并读取我想要的数据,而不向我的asp.net mvc 4应用程序添加任何服务引用

我试过下面的代码

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser = new ChannelFactory<IService1>(basicHttpBinding, endpointAddress).CreateChannel();
DataTable ADUserInfo = ADUser.GetADUserList(strUserName, strFirstName, strLastName, strEmail, domain);
BasicHttpBinding BasicHttpBinding=new BasicHttpBinding();
EndpointAddress EndpointAddress=新的EndpointAddress(“http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser=new ChannelFactory(basicHttpBinding,endpointAddress).CreateChannel();
DataTable ADUserInfo=ADUser.GetADUserList(strUserName、strFirstName、strLastName、strEmail、domain);
但是上面的代码抛出下面的错误

由于EndpointDispatcher上的ContractFilter不匹配,无法在接收器上处理具有操作“”的消息。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)

这看起来确实像是绑定不匹配,因为在WCF配置中,我使用了“customBinding”,但我无法在C代码中定义它,只能找到“BasicHttpBinding”


有人知道我如何通过C#code成功连接到此IIS托管的WCF服务并调用我的“GetADUserList”方法而不向我的MVC应用程序添加服务引用吗?

System.ServiceModel
命名空间中有一个
CustomBinding
类,您可以使用它

Binding customBinding = new CustomBinding(
             new BinaryMessageEncodingBindingElement(),
             new HttpTransportBindingElement 
             { 
               MaxReceivedMessageSize = 2147483647, 
               MaxBufferSize = 2147483647 
             });
EndpointAddress endpointAddress = new EndpointAddress("http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser = new ChannelFactory<IService1>(customBinding, endpointAddress).CreateChannel();
Binding customBinding=新的customBinding(
新的BinaryMessageEncodingBindingElement(),
新的HttpTransportBindingElement
{ 
MaxReceivedMessageSize=2147483647,
MaxBufferSize=2147483647
});
EndpointAddress EndpointAddress=新的EndpointAddress(“http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser=新的ChannelFactory(customBinding,endpointAddress).CreateChannel();

据我所见,您没有在服务器上使用BasicHttpBinding。您正在使用自定义绑定。您还使用了GetData.GetData的契约,而不是IService1。