I'm Back - With WCF Questions
-
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"; } //------
-
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"; } //------
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
-
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"; } //------
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.
-
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
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 -
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.
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 -
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"; } //------
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.