WCF error

Discussion in 'Site Programming, Development and Design' started by wsyeager36, Feb 2, 2012.

  1. I have gotten to the point where my local service runs fine.

    I can also access my production service at:
    http://yeagerte.w07.Winhost.com/yeagerte/YeagerTechWcfService.YeagerTechWcfService.svc

    This signifies that the service is working fine. I can also pull up the service in the WCF Test client tool.

    When I try and access my production service (for debugging pruposes) from within Visual Studio, I get the following error:

    The message could not be processed. This is most likely because the action 'http://tempuri.org/IYeagerTechWcfService/GetCategories' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

    Please also see the image wcf test client 1 which is a similiar error in conjunction with the above error.

    I have searched the web to try and find out additonal info, but am at a stand still...

    I know it's some kind of configuration issue. Can you please let me know what I exactly need to change in the attached config files for it to work successfully? I am just plum old shot of even just getting to this point.....

    You can also see in my code (see images), that the call doesn't even make it into my web service and I have valid objects instantiated in the debug window at the bottom of the image.
     

    Attached Files:

    Last edited by a moderator: Oct 14, 2015
  2. I've narrowed the error down to the security node in the wshttpbinding node.

    I changed it to the following (Message instead of None) which is definitely getting through to the service, but am experiencing another error which should be somewhat easy to fix.

    <security mode="Message">
    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
    </security>
    <!--<security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
    <message clientCredentialType="None" establishSecurityContext="false" negotiateServiceCredential="true" algorithmSuite="Default" />
    </security>-->

    I increased the timeout value on the server config and on the client config, but am still getting the same error (see below).
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"

    [IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
    System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +300
    System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +26
    System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +265

    [WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
    System.Net.HttpWebRequest.GetResponse() +6111651
    System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48

    [CommunicationException: An error occurred while receiving the HTTP response to http://yeagerte.w07.Winhost.com/yeagerte/YeagerTechWcfService.YeagerTechWcfService.svc/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.]
    YeagerTech.Controllers.CategoryController.Index() in C:\Users\byeager\My Documents\Visual Studio 2010\Projects\YeagerTech\YeagerTech\YeagerTech\Controllers\CategoryController.cs:41

    I have tracing enabled in my service, but I can't view any tracelogs because no tracelogs are being written to my server at E:\web\yeagerte\YeagerTech.svclog or E:\web\yeagerte\YeagerTechMessages.svclog

    I need the answers to two questions here:
    1) How can I get tracing to work on the hosting service? The tracing works fine on my local machine. I am able to see the trace logs.
    2) Getting number one to work may solve this whole issue. I need to find out why the original error (as explained above) is happening.

    Here is my tracing configuration in the config file. If anything needs to be changed to enable tracing on your server, please let me know.
    <system.diagnostics>
    <sources>
    <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true">
    <listeners>
    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
    <filter type="" />
    </add>
    <add initializeData="E:\web\yeagerte\YeagerTech.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="traceListener" traceOutputOptions="None">
    <filter type="" />
    </add>
    </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging">
    <listeners>
    <add name="messages" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\web\yeagerte\YeagerTechMessages.svclog"/>
    </listeners>
    </source>
    </sources>
    <trace autoflush="true" />
    </system.diagnostics>
     
    Last edited by a moderator: Oct 14, 2015
  3. OK... Looks like it's defintiely an issue with the way the service is being hosted by Winhost or I need to update the service settings in the config file to resolve the issue.

    I found this link while searching on the web:
    http://forum.Winhost.com/archive/index.php/t-2949.html

    I'm using Entity Framework 4.1 which obviously uses LINQ to retrieve and update data.

    Note that executing these service method on my local machine via my local service works abosultely fine!!!

    The below code is an example of a class in my web service which is serialized back to my local client fine without an issue.

    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.ServiceModel;

    namespace YeagerTechModel
    {
    [Serializable]
    [DataContract(IsReference = true)]
    public partial class Category
    {
    public Category()
    {
    this.Projects = new HashSet<Project>();
    }

    [DataMember]
    public short CategoryID { get; set; }
    [DataMember]
    public string Description { get; set; }

    [DataMember]
    public virtual ICollection<Project> Projects { get; set; }
    }

    }

    If you look at the link I provided above and search for the below context, you will see the same thing that is happening to my situation.

    japinthebox02-06-2010, 03:11 PM
    I've isolated the problem to a small portion of code tested here: http://www.japinthebox.com/ServiceTest/Default.aspx

    The service is implemented in App_Code/Service.cs. It seems to have nothing at all to do with circular references; it just doesn't want to send any [DataContract] objects generated by Linq to SQL.


    02-17-2010, 01:32 AM
    Hello,

    We checked the application logs and the error is:

    "A process serving application pool 'customerPool_2872' suffered a fatal communication error with the Windows Process Activation Service. The process id was '21412'. The data field contains the error number."

    This is usually caused by a coding error that creates a stack overflow.

    Sincerely,

    Lukas
    Winhost

    There's a known stack overflow issue with returning Linq to SQL objects over WCF; when you have mutual references between two tables in the ORM, it'll crash with this same error message. I thought that may have been the case for me, but the same code works fine on my machine, and even when the ORM table has no references to other tables (or to itself, just to be sure), it still crashes.

    What is the next step that can be taken in order to resolve this issue?
     
    Last edited by a moderator: Oct 14, 2015
  4. I expect the Winhost administrators to answer this message. I was assured when I joined that it is 24 x 7 support.

    If I don't get an answer by late tonight, I am serioulsy going to consider moving my host to somebody else that can deal with this type of situation...
     
    Last edited by a moderator: Oct 14, 2015
  5. Through my attached images, I was able to run the project off of my local IIS server instead of Cassini (the Visual Studio development server) and was able to get a response back with no problem whatsoever!

    This proves to me that it's some kind of problem coming from Winhost that is causing the issue of the data not to be serialized back properly.

    What are your proposed solutions?
     

    Attached Files:

  6. Well, Winhost, you have a very short window in which to respond back to me.

    Cytanium hosting already has confirmed they can handle the "issues" contained in this post.
    If I don't receive an answer back very soon, you'll lose my business.
     
  7. Elshadriel

    Elshadriel Winhost Staff

  8. That did not solve the issue...

    A couple of things to point out here...
    I included the following node in my system.web node of the configuration file for both the web service and my client as follows:

    <httpRuntime executionTimeout="3600" maxRequestLength="1048576"/>

    In my web service, I already have the proxycreation and lazyloading already turned off (see below method of web service and attached image)
    Code:
    public IEnumerable<YeagerTechModel.Category> GetCategories()
            {
                YeagerTechEntities DbContext = new YeagerTechEntities();
    
                [B]DbContext.Configuration.ProxyCreationEnabled = false;[/B]
    
                IEnumerable<YeagerTechModel.Category> category = DbContext.Categories.Where(p => p.CategoryID > 0);
    
                CloseConnection(DbContext);
    
                return category;
            }
    
    Below is the code of my edmx file that shows lazyloading is turned off.

    Code:
    <EntityContainer Name="YeagerTechEntities" annotation:[B]LazyLoadingEnabled="false">[/B]
    
    Like I mentioned in one of my last couple of posts, in order for me to see more detailed info, I need to be able to see the tracelogs that the service is supposed to generate.

    The trace logs get generated just fine when I execute locally, but do not get generated when executing from your host. I have the same exact system.diagnostics node for both, except for the file path of where the service is to place the logs. The logs should be on the root of my website, but I do not see them. Maybe it's some kind of permissions issue....

    Code:
    <system.diagnostics>
        <sources>
          <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true">
            <listeners>
              <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                <filter type="" />
              </add>
              <add initializeData="E:\web\yeagerte\YeagerTech.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="traceListener" traceOutputOptions="None">
                <filter type="" />
              </add>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="messages" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\web\yeagerte\YeagerTechMessages.svclog"/>
            </listeners>
          </source>
        </sources>
        <trace autoflush="true" />
      </system.diagnostics>
    
    How come I can't generate the tracelogs on your Winhost servers?

    Please take appropriate action and let me know what I can do next.

    It still has to be some kind of configuration on your servers and or a config file issue.
     

    Attached Files:

    Last edited by a moderator: Oct 14, 2015
  9. Hello Winhost....

    Do you have a reply for me yet?
     
  10. I just tried updating the boldfaced in the server config and the client config from "true" to "false", but with no luck.

    A lot of things I'm reading point to this node as being the one in question that may seem to be causing the problem and I can't get anyone to inform me what the correct configuration should be.

    Can anyone please let me know the exact configuartion I shoud use?

    <system.serviceModel>
    <bindings>
    <wsHttpBinding>
    <binding

    <security mode="Message">
    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    <message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" />
    </security>
     
  11. I also increased the sendtimeout (from 00:01:00 to 00:10:00) property, but still didn't work. I am truly at a loss. Again, it works fine on my lcoal machine via Cassisni or IIS, but not from this hosting service.

    Is there a setting in the config file that I can change to correct this?

    <bindings>
    <wsHttpBinding>
    <binding name="WSHttpBinding_IYeagerTechWcfService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 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="false" algorithmSuite="Default" />
    </security>
    </binding>
    </wsHttpBinding>
    </bindings>
     
  12. OK Winhost, this is your last chance before I switch over to another hosting service that knows what the secuirty node config file properties should be for a web service. I've done all the leg work here...

    I've defintely narrowed it down to the security node inside the binding node. Depending on what changes I make to this node, there are different errors coming out because it is not configured properly. There are different permutations of the security node, so you need to let me know exactly what the specific values for the below properties should be based on how your hosting service works with web services.

    I do not have any specific security in my web service, so please let me know how your hosting service is set up to work with web services and what the below properties should be.

    <security mode="Message">
    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    <message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" />
    </security>
     
    Last edited by a moderator: Oct 14, 2015
  13. This is the Community Forum, not tech support. Tech support is done at: http://support.Winhost.com.
     
    Last edited: Oct 14, 2015
  14. I tried updating the security node again to two different permutations (see at bottom) and am getting the same following error for both:

    "the message contains an invalid or expired security context token or because there is a mismatch between bindings"

    My receivetimeout already is at 10:00 minutes and as you can see in this thread, i'm using the same binding "wshttpbinding" in both the web.config on the client and web.config for the service.

    web.config for service:
    <wsHttpBinding>
    <binding name="WSHttpBinding_IYeagerTechWcfService" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    </binding>
    </wsHttpBinding>

    web.config for client
    <binding name="WSHttpBinding_IYeagerTechWcfService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 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="None">
    <transport clientCredentialType="None" />
    <message establishSecurityContext="false" />
    </security>
    </binding>
    </wsHttpBinding>


    As I mentioned before, this entire process works fine on my local machine using the Cassini (VS development ) web server and changing it up to go through my local IIS web server.

    Please help me get this service running on this hosting site....

    <security mode="None">
    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
    </security>

    <security mode="None">
    <transport clientCredentialType="None" />
    <message establishSecurityContext="false" />
    </security>
     
  15. Finally got it to work....

    Below, are the bullet points I needed to do in order for it to work.
    •First of all, I want to thank Rajesh for pointing me in the right direction as far as IEnumberable vs List in a WCF method.
    •The error message I was receiving did not point me in the right direction. It was basically a "catch all" type of message. In addion, I had tracing set up on my service, but the trace logs wee never written to the production hosting service because it is a shared server --- they simply don't allow a trace log to be generated on a shared server. If this trace log was generated, I'm sure I would have been able to ascertain the problem much sooner.
    •I still don't know why I can return an IEnumerable object via my local web server either through Cassini or IIS as opposed to not being able to do it in a production environment --- at least with the environment with my web hosting service.

    Below code works fine on local machine with Cassini & Local IIS, but not in production environment
    YeagerTechEntities DbContext = new YeagerTechEntities();

    DbContext.Configuration.ProxyCreationEnabled = false;

    IEnumerable category DbContext.Categories.Where(p => p.PriorityID > 0);

    CloseConnection(DbContext);

    return category;
    Below code works fine on local machine with Cassini, Local IIS, and production environment. Note the additon of using a List object. For whatever reason, it appears that WCF does not know what to do with an IEnumerable object in order to pass it back to the client. Still don't know why it worked on my local machine...
    YeagerTechEntities DbContext = new YeagerTechEntities();

    DbContext.Configuration.ProxyCreationEnabled = false;
    DbContext.Database.Connection.Open();

    IEnumerable category = DbContext.Categories.Where(p => p.CategoryID > 0);

    List myCateogries = new List();
    foreach (var cat in category)
    {
    myCateogries.Add(new YeagerTechModel.Category() { CategoryID = cat.CategoryID, Description = cat.Description });
    }

    CloseConnection(DbContext);

    return myCateogries;
    Interface code
    [ServiceContract]
    public interface IYeagerTechWcfService
    {
    [OperationContract]
    List GetCategories();
    In order for my client to function correctly for my View, I still needed to use an IEnumerable object which functions just fine when received back from the above code.

    Client Controller Code
    IEnumerable categoryList = db.GetCategories();
    That all basically takes care of the coding aspect of it. Trying to get the security aspect of it to function was another hurdle. After doing much research and knowing that I can't even appear to get into the web service with the error I was receivng, I had to make the following code additions in my Controller method because it is now known that my hosting service needed security tokens passed into the web service.

    db.ClientCredentials.Windows.ClientCredential.Domain = ConfigurationManager.AppSettings.Get("Domain").ToString();
    db.ClientCredentials.Windows.ClientCredential.UserName = ConfigurationManager.AppSettings.Get("UserName").ToString();
    db.ClientCredentials.Windows.ClientCredential.Password = ConfigurationManager.AppSettings.Get("Password").ToString();
    Config security node

    --------------------------------------------------------------------------------

    I hope this will seriously help all those poor souls out there from suffering the pain I had to go through in order to find the solution. It's a shame that when the original error came out, that Microsoft does not have a thread out there on the web to change an IEnumberable to a List.

    They should also have concrete examples of using the different permutations of the binding node in conjunction with specific hosting environments along with any code that needs to be used with these permutations.
     
  16. Even though I got the application to work with wshttpbinding, there was a lot about the security node that was preventing proper execution of the web pages.

    So, I had to default it to basic http binding and now works a lot faster and fine. In essence, I do not need the ClientCredentials above to process using basichttpbinding.

    If someone can tell me the exact security properties I should use with wshttpbinding, I'd rather use that, so please let me know. Otherwise, the code below I'm using in the config file.
    <basicHttpBinding>
    <binding name="basicHttpBinding_IYeagerTechWcfService" closeTimeout="00:01:00"
    openTimeout="00:10:00" receiveTimeout="24.20:31:23.6470000"
    sendTimeout="00:10:00" bypassProxyOnLocal="false" transferMode="Buffered"
    hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647"
    maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
    useDefaultWebProxy="true" allowCookies="false">
    <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
    maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    <security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None"
    realm="" />
    <!--<message clientCredentialType="UserName"
    algorithmSuite="Default" />-->
    </security>
    </binding>
    </basicHttpBinding>
     

Share This Page