I had been using WCF for some CRUD operations till now. But, now I had a requirement to transfer a file over to WCF service from an MVC action method. After reading a fewer articles, I'm now able to implment it by using MessageContract. I didn't want to
change my existing code, so I added a new binding and a new endpoint.
Now, back in my controller, I'm using my new endpoint like shown below and it is working for me.
var client = new MyServiceClient("BasicHttpBinding_LargeMessageStream_IMyService");
But, this change has broken my existing code where i was instantiating my service like this:
var client = new MyServiceClient();
I was expecting it to use the default endoint. And do not want to make any change to my existing code.
For the time being, I have commented out the old configuration code and everything is working smooth to me. i can use a simple default constructor to instantiate my service class.
But, I'm not sure if changing messageEncoding and transferMode will affect anything.
With WCF 4, the runtime will automatically adds one or more "default endpoints" for you, thereby making the service usable without any configuration, as for this, check this article:
http://msdn.microsoft.com/en-us/library/ee354381.aspx. The default messageEncoding is Text and transferMode is Buffered for the BasicHttpBinding, If you want to change messageEncoding and transferMode,
you need to set the maxBufferSize, MaxReceivedMessageSize and other properties appropriately.
For multiple endpoints for the same service, you need to specify endpoint name for each endpoint, and then when you create client, you need to pass the endpoint name in the constructor. then you can create your client as follows:
using(CalculatorClient client = new CalculatorClient ("endpointConfigurationName"))
{
}
I had been using a default contructor (parameterless constructor) in whole project when there was no need of image uploading (or second endpoint with Mtom/Streamed binding).
It has tought me a lesson now that one should always pass the endpoint name while instatiating a service, does not matter if there is only one endpoint.
To avoid code break, I have removed the old endpoint now and using the same Mtom/Streamed binding endpoint for all my service calls. Is it fine?
If you have only one endpoint for one service contract, you can use the default constructor (parameterless constructor) as follows:
using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
{
string result = client.Hello();
}
ramankashyap
To avoid code break, I have removed the old endpoint now and using the same Mtom/Streamed binding endpoint for all my service calls. Is it fine?
.
You could use MTOM or Steamed in the binding for your endpoint, but you need to update your service reference on the client side or use svcutil command line tool to generate a new config file and import it to the client project.
ramankashyap
Member
178 Points
43 Posts
How to configure default endpoint?
Mar 16, 2012 12:42 PM|LINK
Hi Team,
I had been using WCF for some CRUD operations till now. But, now I had a requirement to transfer a file over to WCF service from an MVC action method. After reading a fewer articles, I'm now able to implment it by using MessageContract. I didn't want to change my existing code, so I added a new binding and a new endpoint.
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IShipment" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> <binding name="BasicHttpBinding_LargeMessageStream_IShipment" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost/Host/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService" contract="ShipmentServiceReference.IMyService" name="basicHttpStream" /> <endpoint address="http://localhost/Host/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LargeMessageStream_IMyService" contract="ShipmentServiceReference.IMyService" name="basicHttpLargeMessageStream" /> </client> </system.serviceModel>Now, back in my controller, I'm using my new endpoint like shown below and it is working for me.
var client = new MyServiceClient("BasicHttpBinding_LargeMessageStream_IMyService");But, this change has broken my existing code where i was instantiating my service like this:
I was expecting it to use the default endoint. And do not want to make any change to my existing code.
For the time being, I have commented out the old configuration code and everything is working smooth to me. i can use a simple default constructor to instantiate my service class.
But, I'm not sure if changing messageEncoding and transferMode will affect anything.
Please advice.
Peter pi - M...
Star
12871 Points
1786 Posts
Re: How to configure default endpoint?
Mar 19, 2012 03:39 AM|LINK
Hi,
With WCF 4, the runtime will automatically adds one or more "default endpoints" for you, thereby making the service usable without any configuration, as for this, check this article: http://msdn.microsoft.com/en-us/library/ee354381.aspx. The default messageEncoding is Text and transferMode is Buffered for the BasicHttpBinding, If you want to change messageEncoding and transferMode, you need to set the maxBufferSize, MaxReceivedMessageSize and other properties appropriately.
Regards,
Peter
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
ramankashyap
Member
178 Points
43 Posts
Re: How to configure default endpoint?
Mar 19, 2012 04:36 PM|LINK
Hello Peter,
Thanks for your reply.
Do I always need to pass the endpoint in the constructor if I'm having multiple endpoints for the same service?
~Raman
kushalrdalal
Contributor
7128 Points
1270 Posts
Re: How to configure default endpoint?
Mar 19, 2012 06:32 PM|LINK
When you create a client you have to pass it into the definition like this -
MyVendorService.MyClient svc = new MyVendorService.MyClient("NetTcp.MyVendor");
My Blog
LinkedIn Profile
Peter pi - M...
Star
12871 Points
1786 Posts
Re: How to configure default endpoint?
Mar 20, 2012 02:28 AM|LINK
Hi,
For multiple endpoints for the same service, you need to specify endpoint name for each endpoint, and then when you create client, you need to pass the endpoint name in the constructor. then you can create your client as follows:
using(CalculatorClient client = new CalculatorClient ("endpointConfigurationName")) { }Please check this article: http://msdn.microsoft.com/en-us/library/ms733133.aspx
Regards,
Peter
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
ramankashyap
Member
178 Points
43 Posts
Re: How to configure default endpoint?
Mar 20, 2012 10:08 AM|LINK
Thanks Guys.
But, it will break my existing code.
I had been using a default contructor (parameterless constructor) in whole project when there was no need of image uploading (or second endpoint with Mtom/Streamed binding).
It has tought me a lesson now that one should always pass the endpoint name while instatiating a service, does not matter if there is only one endpoint.
To avoid code break, I have removed the old endpoint now and using the same Mtom/Streamed binding endpoint for all my service calls. Is it fine?
~Raman
Peter pi - M...
Star
12871 Points
1786 Posts
Re: How to configure default endpoint?
Mar 21, 2012 06:36 AM|LINK
If you have only one endpoint for one service contract, you can use the default constructor (parameterless constructor) as follows:
using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client()) { string result = client.Hello(); }You could use MTOM or Steamed in the binding for your endpoint, but you need to update your service reference on the client side or use svcutil command line tool to generate a new config file and import it to the client project.
Regards,
Peter
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
ramankashyap
Member
178 Points
43 Posts
Re: How to configure default endpoint?
Mar 21, 2012 10:13 AM|LINK
Thanks a lot Peter. I have done all changes to my config on both ends, and it is working for me. I just wanted to know the side-effects of it.
Thanks again :)