Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want create dynamic WCF service channel in VS-2010 using ChannelFactory as follows.

I have one WCF service which is calling another WCF service using ChannelFactory as follows,

C#
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” file of called service as follows,

C#
<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>


factory and proxy is working fine but when “Invoke” method is executed it gives error as follows

There was no endpoint listening at http://localhost:81/IService.Service.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details


Server stack trace:
C#
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)


Exception rethrown at [0]:
C#
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)


[Edit - CHill60]
OP has already tried this solution Error: There was no endpoint listening at...[^]. I have deleted my solution
Posted
Updated 29-May-13 3:25am
v3

1 solution

Thanks all

I changed some code given bellow check out and now its working fine,...

C#
WSHttpBinding myBinding = new WSHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress(_URL);
using (ChannelFactory<iservice> factory = new ChannelFactory<iservice>(myBinding))
{
	factory.Open();
	object[] parameters = new object[1];
	parameters[0] = _id;
	ISchedule 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();
}


you can ether execute by directly proxy, but it restrict you to particular method only as,

C#
using ((IDisposable)proxy)
{
    proxy.DoExecute(_id);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900