2

我想使用 ChannelFactory 在 VS-2010 中创建动态 WCF 服务通道,如下所示。

我有一个 WCF 服务,它使用 ChannelFactory 调用另一个 WCF 服务,如下所示,

BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress(_endpointConfigurationName);
using (ChannelFactory<IService> factory = new ChannelFactory< IService >(myBinding))
{
factory.Open();
       object[] parameters = new object[1];
       parameters[0] = _documentId;
       IService proxy = factory.CreateChannel(myEndpoint);
       if (proxy == null)
        return;
       MethodInfo mi = proxy.GetType().GetMethod("DoExecute");
       if (mi == null)
        return;
       var serviceResult = mi.Invoke(proxy, parameters); 
       factory.Close();
}

被调用服务的“Web.config”文件如下,

<services>
      <service name="IService.Service">
        <endpoint address="ws" binding="wsHttpBinding" name="wsHttpBinding_IFTPUploaderService" contract="Service.IService ">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       <host>
            <baseAddresses>
                    <add baseAddress="http://localhost:8752/Service/" />
            </baseAddresses>
       </host>
</service>
</services>

工厂和代理工作正常,但是当执行“调用”方法时,它会给出如下错误

没有http://localhost:81/IService.Service.svc?wsdl可以接受消息的端点监听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)

服务器堆栈跟踪

at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

在 [0] 处重新抛出异常

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at SchedulerService.Service.IService.DoExecute(String id)
4

0 回答 0