在网上有很多动态调用webservice的代码,可惜就是没有找到调用wcf的,有哪位高手写过,或用过,请贴出来分享一下谢谢

解决方案 »

  1.   

    http://hi.baidu.com/meback/blog/item/c140495447258e5d564e0006.html
    楼主可以看一下
      

  2.   

    你的意思是不写代理类也不用vs.net生成的代理类?那可以用ajax.net控件调用,只需要知道wcf地址就行http://peterkellner.net/2008/09/14/wcf-web-service-json-vs2008/还有一种方法是wcf SDK例子中vb客户端调用方式,也不用接口。
      

  3.   

    ajax.net控件调用 那是asp.net的程序  winfrom程序还是没找到相关资料(不用接口)wcf SDK例子 我这没安装 有SDK例子的下载的地址吗?
      

  4.   

    写个工厂类生成就可以了,你可以看看这个类 ChannelFactory
      

  5.   


    兄弟 ChannelFactory不行啊。错误提示: 传递给通用 ChannelFactory 类的类型参数必须是接口类型。
    代码如下:public static object ExecuteMethod<T>(string pUrl,string pMethodName, params object[] pParams)   
           {   
               EndpointAddress address = new EndpointAddress(pUrl);   
               Binding bindinginstance = null;   
               BasicHttpBinding ws = new BasicHttpBinding();
               ws.MaxReceivedMessageSize = 65535000;
               bindinginstance = ws;
               using (ChannelFactory<T> channel = new ChannelFactory<T>(bindinginstance,address))   
               {   
                   T instance = channel.CreateChannel();   
                   using (instance as IDisposable)   
                   {   
                       try  
                       {   
                           Type type = typeof(T);   
                           MethodInfo mi = type.GetMethod(pMethodName);   
                           return mi.Invoke(instance, pParams);   
                       }   
                       catch (TimeoutException)   
                       {   
                           (instance as ICommunicationObject).Abort();   
                           throw;   
                       }   
                       catch (CommunicationException)   
                       {   
                           (instance as ICommunicationObject).Abort();   
                           throw;   
                       }   
                       catch (Exception vErr)   
                       {   
                           (instance as ICommunicationObject).Abort();   
                           throw;   
                       }   
                   }   
               }   
           }
            
      

  6.   

    这事因为你加了 using (instance as IDisposable)   这个判断吧.你继承那个接口了吗 生成通道的方法是对的
      

  7.   

    ChannelFactory 是一个抽象类  不是接口 
    错误发生点:
     using (ChannelFactory<T> channel = new ChannelFactory<T>(bindinginstance,address))