Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. I'm Back - With WCF Questions

I'm Back - With WCF Questions

Scheduled Pinned Locked Moved WCF and WF
csharpwcfvisual-studiowpf
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    realJSOP
    wrote on last edited by
    #1

    Using .Net 3.5, and I'm trying to create a WCF client to communicate with an ASMX web service (and no, the service itself won't be converted to WCF, so don't bother suggesting it). Alright. I added a service reference to my web service, and the IDE added the necessary code, and put a lot of binding and endpoint crap into the app.config. Not wanting all of that data in the app.config, I tried to put it all in the code inside a wrapper class. I created the following base class, in which I create an instance of a WSHttpBinding object, as well as an EndpointAddress object. The constructor accepts the uri for the endpoint, and the binding name that were found in the app.config file. I also set all of the properties in the binding object to what was specified in the app.config.

    public class WCFServiceBase
    {
    	protected EndpointAddress m\_endpoint = null;
    	protected WSHttpBinding m\_binding = null;
    
    
    	//--------------------------------------------------------------------------------
    	/// /// Constructor - builds the endpoint based on the specified uri, and the 
    	/// binding (as well as setting all of the values that would normally go 
    	/// in the config file).
    	/// 
    	public WCFServiceBase(string uri, string bindingName)
    	{
    		m\_endpoint = new EndpointAddress(uri);
    		m\_binding = new WSHttpBinding();
    		m\_binding.Name = bindingName;
    		m\_binding.CloseTimeout = TimeSpan.Parse("00:01:00");
    		m\_binding.OpenTimeout = TimeSpan.Parse("00:01:00");
    		m\_binding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
    		m\_binding.SendTimeout = TimeSpan.Parse("00:01:00");
    		m\_binding.AllowCookies = false;
    		m\_binding.BypassProxyOnLocal = false;
    		m\_binding.TransactionFlow = false;
    		m\_binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
    		m\_binding.MaxBufferPoolSize = 524288;
    		m\_binding.MaxReceivedMessageSize = 65536;
    		m\_binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text;
    		m\_binding.TextEncoding = System.Text.Encoding.UTF8;
    		m\_binding.UseDefaultWebProxy = true;
    	}
    }
    

    Next, I created a class derived from the base class above:

    public partial class WCFUserService : WCFServiceBase
    {
    	private WCFUsers.AuthSoapHeader	m\_soapHeader = new WCFUsers.AuthSoapHeader();
    
    	public WCFUserService()
    		: base("http://1.2.3.4/\_ws/UsersService.asmx", "UsersServiceSoap")
    	{
    		m\_soapHeader.username = "MyServiceUser";
    		m\_soapHeader.password = "MyServicePassword";
    	}
    
    	//------
    
    S B P 3 Replies Last reply
    0
    • R realJSOP

      Using .Net 3.5, and I'm trying to create a WCF client to communicate with an ASMX web service (and no, the service itself won't be converted to WCF, so don't bother suggesting it). Alright. I added a service reference to my web service, and the IDE added the necessary code, and put a lot of binding and endpoint crap into the app.config. Not wanting all of that data in the app.config, I tried to put it all in the code inside a wrapper class. I created the following base class, in which I create an instance of a WSHttpBinding object, as well as an EndpointAddress object. The constructor accepts the uri for the endpoint, and the binding name that were found in the app.config file. I also set all of the properties in the binding object to what was specified in the app.config.

      public class WCFServiceBase
      {
      	protected EndpointAddress m\_endpoint = null;
      	protected WSHttpBinding m\_binding = null;
      
      
      	//--------------------------------------------------------------------------------
      	/// /// Constructor - builds the endpoint based on the specified uri, and the 
      	/// binding (as well as setting all of the values that would normally go 
      	/// in the config file).
      	/// 
      	public WCFServiceBase(string uri, string bindingName)
      	{
      		m\_endpoint = new EndpointAddress(uri);
      		m\_binding = new WSHttpBinding();
      		m\_binding.Name = bindingName;
      		m\_binding.CloseTimeout = TimeSpan.Parse("00:01:00");
      		m\_binding.OpenTimeout = TimeSpan.Parse("00:01:00");
      		m\_binding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
      		m\_binding.SendTimeout = TimeSpan.Parse("00:01:00");
      		m\_binding.AllowCookies = false;
      		m\_binding.BypassProxyOnLocal = false;
      		m\_binding.TransactionFlow = false;
      		m\_binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
      		m\_binding.MaxBufferPoolSize = 524288;
      		m\_binding.MaxReceivedMessageSize = 65536;
      		m\_binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text;
      		m\_binding.TextEncoding = System.Text.Encoding.UTF8;
      		m\_binding.UseDefaultWebProxy = true;
      	}
      }
      

      Next, I created a class derived from the base class above:

      public partial class WCFUserService : WCFServiceBase
      {
      	private WCFUsers.AuthSoapHeader	m\_soapHeader = new WCFUsers.AuthSoapHeader();
      
      	public WCFUserService()
      		: base("http://1.2.3.4/\_ws/UsersService.asmx", "UsersServiceSoap")
      	{
      		m\_soapHeader.username = "MyServiceUser";
      		m\_soapHeader.password = "MyServicePassword";
      	}
      
      	//------
      
      S Offline
      S Offline
      Sacha Barber
      wrote on last edited by
      #2

      John I don't know the exact answer to this, but might I suggest you ask comms guru Roman Kiss (here at codeproject) he will know for sure.

      Sacha Barber

      • Microsoft Visual C# MVP 2008
      • Codeproject MVP 2008

      Your best friend is you. I'm my best friend too. We share the same views, and hardly ever argue My Blog : sachabarber.net

      R 1 Reply Last reply
      0
      • R realJSOP

        Using .Net 3.5, and I'm trying to create a WCF client to communicate with an ASMX web service (and no, the service itself won't be converted to WCF, so don't bother suggesting it). Alright. I added a service reference to my web service, and the IDE added the necessary code, and put a lot of binding and endpoint crap into the app.config. Not wanting all of that data in the app.config, I tried to put it all in the code inside a wrapper class. I created the following base class, in which I create an instance of a WSHttpBinding object, as well as an EndpointAddress object. The constructor accepts the uri for the endpoint, and the binding name that were found in the app.config file. I also set all of the properties in the binding object to what was specified in the app.config.

        public class WCFServiceBase
        {
        	protected EndpointAddress m\_endpoint = null;
        	protected WSHttpBinding m\_binding = null;
        
        
        	//--------------------------------------------------------------------------------
        	/// /// Constructor - builds the endpoint based on the specified uri, and the 
        	/// binding (as well as setting all of the values that would normally go 
        	/// in the config file).
        	/// 
        	public WCFServiceBase(string uri, string bindingName)
        	{
        		m\_endpoint = new EndpointAddress(uri);
        		m\_binding = new WSHttpBinding();
        		m\_binding.Name = bindingName;
        		m\_binding.CloseTimeout = TimeSpan.Parse("00:01:00");
        		m\_binding.OpenTimeout = TimeSpan.Parse("00:01:00");
        		m\_binding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
        		m\_binding.SendTimeout = TimeSpan.Parse("00:01:00");
        		m\_binding.AllowCookies = false;
        		m\_binding.BypassProxyOnLocal = false;
        		m\_binding.TransactionFlow = false;
        		m\_binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
        		m\_binding.MaxBufferPoolSize = 524288;
        		m\_binding.MaxReceivedMessageSize = 65536;
        		m\_binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text;
        		m\_binding.TextEncoding = System.Text.Encoding.UTF8;
        		m\_binding.UseDefaultWebProxy = true;
        	}
        }
        

        Next, I created a class derived from the base class above:

        public partial class WCFUserService : WCFServiceBase
        {
        	private WCFUsers.AuthSoapHeader	m\_soapHeader = new WCFUsers.AuthSoapHeader();
        
        	public WCFUserService()
        		: base("http://1.2.3.4/\_ws/UsersService.asmx", "UsersServiceSoap")
        	{
        		m\_soapHeader.username = "MyServiceUser";
        		m\_soapHeader.password = "MyServicePassword";
        	}
        
        	//------
        
        B Offline
        B Offline
        Bert delaVega
        wrote on last edited by
        #3

        Hi John. Are you still having trouble with this? I don't see any glaring problem with what you posted. I'm doing some WCF stuff today so I might just import this code into my project to call a dummy service and take a look. When you delete the system.serviceModel from your app.config, what type of exception gets generated? Also, it sounds like you're using the "Add a Service Reference" to generate the proxy. Try using SVCUTIL (VS tools/command prompt) as it allows for better control of the generated client proxy classes. I recall reading somewhere that adding a service reference uses a different mechanism than svcutil.exe. For example, you can tell svcutil to not generate app.config entries. It's possible that using the other method creates an attribute tag in the generated class that points to the app.config for it's attributes instead of your class.

        R 1 Reply Last reply
        0
        • S Sacha Barber

          John I don't know the exact answer to this, but might I suggest you ask comms guru Roman Kiss (here at codeproject) he will know for sure.

          Sacha Barber

          • Microsoft Visual C# MVP 2008
          • Codeproject MVP 2008

          Your best friend is you. I'm my best friend too. We share the same views, and hardly ever argue My Blog : sachabarber.net

          R Offline
          R Offline
          realJSOP
          wrote on last edited by
          #4

          okie dokie. :)

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          1 Reply Last reply
          0
          • B Bert delaVega

            Hi John. Are you still having trouble with this? I don't see any glaring problem with what you posted. I'm doing some WCF stuff today so I might just import this code into my project to call a dummy service and take a look. When you delete the system.serviceModel from your app.config, what type of exception gets generated? Also, it sounds like you're using the "Add a Service Reference" to generate the proxy. Try using SVCUTIL (VS tools/command prompt) as it allows for better control of the generated client proxy classes. I recall reading somewhere that adding a service reference uses a different mechanism than svcutil.exe. For example, you can tell svcutil to not generate app.config entries. It's possible that using the other method creates an attribute tag in the generated class that points to the app.config for it's attributes instead of your class.

            R Offline
            R Offline
            realJSOP
            wrote on last edited by
            #5

            The execption doesn't indicate what the problem is (to me, anyway). It occurs when I call the GetGlobalValueBySetting() method, and is "object is not set to the value of a reference".

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            1 Reply Last reply
            0
            • R realJSOP

              Using .Net 3.5, and I'm trying to create a WCF client to communicate with an ASMX web service (and no, the service itself won't be converted to WCF, so don't bother suggesting it). Alright. I added a service reference to my web service, and the IDE added the necessary code, and put a lot of binding and endpoint crap into the app.config. Not wanting all of that data in the app.config, I tried to put it all in the code inside a wrapper class. I created the following base class, in which I create an instance of a WSHttpBinding object, as well as an EndpointAddress object. The constructor accepts the uri for the endpoint, and the binding name that were found in the app.config file. I also set all of the properties in the binding object to what was specified in the app.config.

              public class WCFServiceBase
              {
              	protected EndpointAddress m\_endpoint = null;
              	protected WSHttpBinding m\_binding = null;
              
              
              	//--------------------------------------------------------------------------------
              	/// /// Constructor - builds the endpoint based on the specified uri, and the 
              	/// binding (as well as setting all of the values that would normally go 
              	/// in the config file).
              	/// 
              	public WCFServiceBase(string uri, string bindingName)
              	{
              		m\_endpoint = new EndpointAddress(uri);
              		m\_binding = new WSHttpBinding();
              		m\_binding.Name = bindingName;
              		m\_binding.CloseTimeout = TimeSpan.Parse("00:01:00");
              		m\_binding.OpenTimeout = TimeSpan.Parse("00:01:00");
              		m\_binding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
              		m\_binding.SendTimeout = TimeSpan.Parse("00:01:00");
              		m\_binding.AllowCookies = false;
              		m\_binding.BypassProxyOnLocal = false;
              		m\_binding.TransactionFlow = false;
              		m\_binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
              		m\_binding.MaxBufferPoolSize = 524288;
              		m\_binding.MaxReceivedMessageSize = 65536;
              		m\_binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text;
              		m\_binding.TextEncoding = System.Text.Encoding.UTF8;
              		m\_binding.UseDefaultWebProxy = true;
              	}
              }
              

              Next, I created a class derived from the base class above:

              public partial class WCFUserService : WCFServiceBase
              {
              	private WCFUsers.AuthSoapHeader	m\_soapHeader = new WCFUsers.AuthSoapHeader();
              
              	public WCFUserService()
              		: base("http://1.2.3.4/\_ws/UsersService.asmx", "UsersServiceSoap")
              	{
              		m\_soapHeader.username = "MyServiceUser";
              		m\_soapHeader.password = "MyServicePassword";
              	}
              
              	//------
              
              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              John - what I don't see here is anything to do with creating your channel. I would expect to see something along the lines of

              WCFUsers.UsersServiceSoapClient proxy = ChannelFactory<WCFUsers.UsersServiceSoapClient>.CreateChannel(m_binding, m_endpoint);

              Deja View - the feeling that you've seen this post before.

              My blog | My articles | MoXAML PowerToys

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups