Publishing A WCF Service - asp.net

I am deploying a web application to a remote server. I set up IIS 7 and the site comes up.
As part of the web application there is a service reference to a wcf service.
All of this works fine on my localhost everything runs.
I never did anything with the service itself on the deployment server. I just set up the web application in IIS. Now I am getting an socket exception error that could be from a few thing, I just want to eliminate my options......
My question is do I have to publish the service as part of my deployment process or since I published the web application with a service reference attached to it I should be ok?
Here is my web config portion of the service as you can see there is a reference to localhost (this cant be good) how is this resolved?
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHSSWcfServices" 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>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49506/IHSSWcfServices.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHSSWcfServices"
contract="ServiceReference1.IHSSWcfServices" name="BasicHttpBinding_IHSSWcfServices" />
</client>
</system.serviceModel>

You do not have to publish the service as part of the deployment process for the application(otherwise, an ASP.NET application could never talk to an externally published service).
Just make sure that the service address you are trying to communicate with is the actual address of the hosted service (and not localhost, for instance, which would work on your machine, but not once it is deployed).
If you are writing the service and the client, the service does have to be deployed somewhere, and that somewhere must be accessible to the deployed location of the client. The deployment of the service is, however, independent of the deployment of the client.

Your system.ServiceModel section in config is clearly referencing the localhost. Try to change it to point to the actual IIS URL

Related

WCF configuration for .svc host on ASP.NET

I have a WCF web service which is hosted at a .svc file by ASP.NET. .svc file contains following configuration:
<%# ServiceHost Language="C#" Debug="true" Service="assembly.IPriceListProvider, assembly" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
web.config contains configuration of the WCF. Here goes the binding configuration:
<binding name="basicHttpBinding_PriceListProvider" maxBufferSize="10485760"
maxReceivedMessageSize="10485760">
<readerQuotas maxArrayLength="16384000" />
</binding>
To test the service, I click on .svc file and click F5. WCF Test Client is opened. But the configuration has changed. The values which I've explicitly defined have now default values:
<binding name="basicHttpBindingEndPoint_PriceListProvider" 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>
Why does the configuration change? How do I persist original values?
I've heard something about simplified .svc configuration: a default binding for .svc is configured even if you don't specify it explicitly in web.config. Can it be the case?
The values for maxBufferSize and maxReceivedMessageSize are not propagated to the WSDL file that is published by your service. That´s why the wcf test client is unable to retrieve them and takes default values.
You can still change the values with the SvcConfigEditor every time you start the wcf test client. Therefor perform a right click on the config file in the wcf test client and look for bindings. But the changes will be lost, the next time you start the client.
You can also test your service with a self written client and set the values there like shown in the following example.
BasicHttpBinding binding= new BasicHttpBinding();
binding.MaxRecievedMessageSize = yourValue;
EndpointAddress endpointAddress = new EndpointAddress("the address");
ClientForContract client= new ClientForContract (binding,endpointAddress);
client.TheMethod();
client.Close();
Hope this helps!

Slowing web application with WCF on timely request

I am new for the WCF, i have web application which uses WCF Service as a data access layer. I am using wcf service library and hosterd it on IIS7. It works fine for few initial service calls but hangs an application for further request. When i reset IIS , then again it is working fine for some time.
Below is the service configuration in web.config of web app
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IRoaster" closeTimeout="00:10:00"
openTimeout="00:01:00" receiveTimeout="00:02:00" sendTimeout="00:03:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="199999488" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://asdf.com/RoasterService/RoasterService.Roaster.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRoaster"
contract="RoasterService.IRoaster" name="WSHttpBinding_IRoaster">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
Is there if i comment all the wcf call then for dummy values application works fine. please suggest the appropriate solution
You're probably not disposing the WCF client instance at the end of the request. Look at this post for the gotcha's in working with WCF clients.

Config troubles consuming Web Service ASP.Net (Not WCF)

Well, i can't solve the following problem.
I have the next:
* A Web Service development in C# + .Net Framework 3.5 + iBatis (VS2010) with some WebMethods.
* The Web Service run on a local server, in IIS 5.1 (http://localhost/BookService/BookService.asmx).
* An application WF+C# + .Net Framework 3.5 (VS2010) where the BO layer have a service reference to the Web Service.
The app.config generated by Service Reference is:
<?xml version="1.0" encoding="utf-8" ?>´
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BookServiceSoap" 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>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.0.2.15/BookService/BooksService.asmx"
binding="basicHttpBinding" bindingConfiguration="BookServiceSoap"
contract="BookService.BookServiceSoap" name="BookServiceSoap" />
</client>
</system.serviceModel>
</configuration>
I'm trying to connecting me to the web service making for example
BookService.BookServiceSoapClient query = new BookService.BookServiceSoapClient("BookServiceSoap","http://10.0.2.15/BookService/BookService.asmx");
or with out the endpointname and the url
BookService.BookServiceSoapClient query = new BookService.BookServiceSoapClient();
But in execution time appears the following message
Could not find endpoint element with name 'BookServiceSoap'
and contract 'BookService.BookServiceSoap' in the ServiceModel
client configuration section. This might be because no
configuration file was found for your application, or because
no endpoint element matching this name could be found in the client element.
Can somebody show me un right example to call for example the method HelloWorld.
Regards!

WCF impersonation exception in ASP.NET

I have a solution in which a Silverlight application calls a WCF service (self-hosted in console application) which we'll call A, which calls another WCF service (hosted in IIS) which we'll call B.
WCF service A contains two standard methods and one methods which uses impersonation and calls WCF service B. I have no problems when I try calling WCF service A from Silverlight, including the call with the impersonation, but when I try to do the same from a ASP.NET application I get the following exception when I call WCF service B from the impersonation methods:
Could not load file or assembly 'System.IdentityModel.Selectors, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
Exception from HRESULT: 0x80070542
Here is the relevant part of my web.config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IPrint">
<binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
maxSessionSize="2048">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Ntlm"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
<binding name="WebHttpBinding_IClientAccessPolicy">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/ClientAppsWCF" binding="customBinding"
bindingConfiguration="CustomBinding_IPrint" contract="ClientApps.IPrint"
name="CustomBinding_IPrint">
<identity>
<userPrincipalName value="ytal#ifnsystems.com" />
</identity>
</endpoint>
<endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_IClientAccessPolicy"
contract="ClientApps.IClientAccessPolicy" name="WebHttpBinding_IClientAccessPolicy" />
</client>
</system.serviceModel>
Will appreciate if someone can help me out with this.
I'm not sure about the exact problem, but I'll try to help you from similar erros regarding impersonation.
It could be some things:
Kerberos Authentication:
Since your service A is self hosted, it sends the host crendential to Service B (on IIS).
Try checking on Event viewer, on Application and Security tabs, if the users was logged ok. See if it using Kerberos or NTLM. If it goes back to Kerberos, check the SPN and if the user is trusted for delegation in Active Diretory.
Check if the assembly properly signed.
Check if the user (host A) has permission to acess the assembly you are trying to load.

WCF Error - unexpected response: (400) Bad Request

I'm having trouble finding an answer for this problem. Most similar posts lean seem to be fixed by adjusting some of the maximum size settings in the web.config file. However, none of those suggestions have fixed my issue.
To give a little more background, I'm porting a asmx web service, to a WCF web service hosted in Windows Azure. This problem came up during testing. If I pass a small number of transactions to my webservice in a single call, it tends to work just fine. This error come up though when my transaction size gets around 50-60 (transactions). Serialized to xml, the file size is around 300K, so it's nothing insanely large. But it does tend to lean towards a size issue.
Also, turning on WCF tracing, I found the following exception occuring:
System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
at System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&amp; requestException)
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
So from the exception, it looks as though one of the settings if off in my web.config, but here is what that looks like:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="MetadataEnabled">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="8081"/>
<add scheme="https" port="444"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
<dataContractSerializer maxItemsInObjectGraph="111024000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled">
<endpoint name="HttpEndpoint"
address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttp"
contract="Bandicoot.CORE.IRepricer" />
<endpoint name="HttpMetadata"
address="contract"
binding="mexHttpBinding"
bindingConfiguration="mexBinding"
contract="Bandicoot.CORE.Stack" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Core"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize="111024000"
messageEncoding="Text" maxBufferPoolSize="111024000"
textEncoding="UTF-8">
<readerQuotas maxBytesPerRead="111024000"
maxArrayLength="111024000"
maxStringContentLength="111024000"/>
<security mode="None"/>
</binding>
</wsHttpBinding>
<mexHttpBinding>
<binding name="mexBinding"/>
</mexHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
Does anyone have any other suggestions, or is there something mis-configured in my web.config that I'm just not seeing?
Thanks for any advice!
Edit: Here is the settings from my client's app.config
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="14194304" maxBufferPoolSize="14194304" maxReceivedMessageSize="14194304"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="1000" maxStringContentLength="111024000"
maxArrayLength="111024000" maxBytesPerRead="1024000" maxNameTableCharCount="111024000" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
Edit: adding addition client information:
<client>
<endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE"
name="BasicHttpBinding_CORE" />
</client>
Edit: Attempted changing the service bindings to basicHttpBinding - config changes:
<basicHttpBinding>
<binding name="basicHttp" maxReceivedMessageSize="111024000"
messageEncoding="Text" maxBufferPoolSize="111024000"
textEncoding="UTF-8">
<readerQuotas maxArrayLength="111024000" maxBytesPerRead="111024000" maxStringContentLength="111024000"/>
<security mode="None" />
</binding>
</basicHttpBinding>
<service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled">
<endpoint binding="basicHttpBinding"
bindingConfiguration="basicHttp"
contract="Bandicoot.CORE.IRepricer" />
<endpoint address="mex"
binding="mexHttpBinding"
bindingConfiguration="mexBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Core"/>
</baseAddresses>
</host>
</service>
And the client's app.config as well for reference:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_CORE" 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="100000000"
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>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE"
name="BasicHttpBinding_CORE" />
</client>
You need to be setting the maxReceivedMessageSize on the client (where the message you're returning from your service is incoming) - in its app.config or web.config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize="111024000"
messageEncoding="Text" maxBufferPoolSize="111024000"
textEncoding="UTF-8">
<readerQuotas maxBytesPerRead="111024000"
maxArrayLength="111024000"
maxStringContentLength="111024000"/>
<security mode="None"/>
</binding>
</wsHttpBinding>
<mexHttpBinding>
<binding name="mexBinding"/>
</mexHttpBinding>
</bindings>
<client name="whatever">
<endpoint name="HttpEndpoint"
address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttp"
contract="Bandicoot.CORE.IRepricer" />
</client>
</system.serviceModel>
The default value for maxReceivedMessageSize is 64K, unless you change it.
I finally figured this one out this morning. The problem was that my service was not using the configuration settings that I thought it was. The reason? The service name in the configuration needs to be a fully qualified path to the service being implemented.
I found this link helpful figuring it out.
I found it a little odd that my service worked without pointing it to an actual endpoint, I guess it just uses a series of default values and if you want something different you can configure them in the web.config? I think this explains why I was getting a basicHttpBinding when I consumed the webservice in my client, instead of wsHttpBinding.
Took a few days to figure it out, but was educational. Thanks for the suggestions!
I had the same error and the cause was revealed to be a configuration error, too.
But in my case this was, like marc_s already posted, the maxReceivedMessageSize setting on the server side. The server was still using its default configuration, which was as low as 64 kb.
As obvious as this now sounds, that long it took me to find out that the error was not on my (client) side.
I hope that this may help someone else.
Hi Question Poster "Brosto"!
This supplements your Nov 17 '10 at 15:29 answer.
We had a “fun”, or should I say “educational” Production Deployment Testing issue today that took most of the day to resolve, and it was literally caused by one keystroke. We only confirmed the source of the problem, after we found out the problem disappeared after the Web Farm was fully deployed.
Here was the cause. When we test our Production Deployment, and do so against a “Single Server” by changing our hosts file, we are bypassing the Load Balancer, and the call to the Single Server ends up going over the default http port 80! When we test against the “Load Balancer”, the call to the Single Server from the Load Balancer, ends up going over the Load Balancer defined port 81!
Since the Service Endpoint Address must be “fully qualified”, to enable the service to find its Custom Bindings, the Services.config file on the Single Server must be changed to reflect the difference between “Single Server” vs “Load Balanced Server” endpoint connections, as follows:
Single Server connection:
endpoint address="http://www.myserver.com:80/Services/MyService.svc"
Load Balanced Server connection:
endpoint address="http://www.myserver.com:81/Services/MyService.svc"
My boss correctly diagnosed the core problem early, saying that the server was acting like the custom bindings were being ignored and the defaults were being used instead. After showing him your comment above where you mention the requirement of “fully qualified” service endpoint address, he realized that the host file redirection was causing our browser request to go to the Single Server over default port 80, instead of the Load Balanced port 81, which in effect altered the fully qualified service endpoint address, which caused the server to ignore the custom bindings and revert to default settings. Please note that it did NOT fail to call the service, it only failed to bind the custom bindings!
Hopefully someone will remember this posting the next time we Production Test a Service with custom bindings :)

Resources