WCF: The underlying connection was closed: The connection was closed unexpectedly
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: WCF: The underlying connection was closed: The connection was closed unexpectedly

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Posts
    4

    WCF: The underlying connection was closed: The connection was closed unexpectedly

    1) Server:

    Service interface:

    PHP Code:
    [OperationContract(Action Service.RequestActionReplyAction Service.ReplyAction)]
    Message DoWork(Message name); 
    Implementation:

    PHP Code:
    public class Service IService
    {
        public const 
    string ReplyAction "http://localhost/Service/Message_ReplyAction";
        public const 
    string RequestAction "http://localhost/Service/Message_RequestAction";

        public 
    Message DoWork(Message requestXml)
        {
            
    using (StreamWriter writer File.CreateText(@"E:\Projekti\WCF\WcfTestIIS\Service\Body.xml"))
            {
                
    writer.WriteLine(requestXml.ToString());
            }
            
    Message response Message.CreateMessage(MessageVersion.Default, ReplyActionrequestXml.ToString());

            return 
    response;
        }

    web.config:

    PHP Code:
    <system.serviceModel>
        <
    serviceHostingEnvironment>
          <
    baseAddressPrefixFilters>
            <
    add prefix="http://localhost:80/"/>
          </
    baseAddressPrefixFilters>
        </
    serviceHostingEnvironment>
        <
    behaviors>
            <
    serviceBehaviors>
                <
    behavior name="Service.ServiceBehavior">
                    <
    serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/Service/Service.svc" />
                    <
    serviceDebug includeExceptionDetailInFaults="true" />
                    <
    MyInspector />
                </
    behavior>
            </
    serviceBehaviors>
        </
    behaviors>
        <
    services>
            <
    service behaviorConfiguration="Service.ServiceBehavior" name="Service.Service">
                <
    endpoint 
                    address
    ="http://localhost/Service/Service.svc" 
                    
    binding="basicHttpBinding" 
                    
    contract="Service.IService">
                    <
    identity>
                        <
    dns value="localhost" />
                    </
    identity>
                </
    endpoint>
                <
    endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
            </
    service>
        </
    services>
        <
    extensions>
          <
    behaviorExtensions>
            <
    add name="MyInspector" type="Service.MessageInspectorExtension, Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
          </
    behaviorExtensions>
        </
    extensions>
    </
    system.serviceModel
    2) Client:

    PHP Code:
    ServiceClient client = new ServiceClient();
    string RequestAction "http://localhost/Service/Message_RequestAction";
    MessageVersion msgVersion MessageVersion.CreateVersion(EnvelopeVersion.Soap11AddressingVersion.None);
    Message request Message.CreateMessage(msgVersionRequestAction"Test message");
    Message reply client.DoWork(request);
    client.Close(); 
    web.config:

    PHP Code:
    <system.serviceModel>
        <
    bindings>
            <
    basicHttpBinding>
                <
    binding name="BasicHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                 
    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                 
    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                    <
    readerQuotas maxDepth="32" 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>
        </
    bindings>
        <
    client>
            <
    endpoint name="BasicHttpBinding_IService"
                            
    address="http://localhost/Service/Service.svc" 
                            
    binding="basicHttpBinding" 
                            
    bindingConfiguration="BasicHttpBinding_IService" 
                            
    contract="ServiceReference.IService" />
        </
    client>
    </
    system.serviceModel
    As you can see I use basicHttpBinding on server side that uses Soap 1.1. That's why I've used the code above on client side to explicitly set Soap 1.1 as well (I'm not sure if that is right way).

    I'm not sure why I'm getting the error:

    "The underlying connection was closed: The connection was closed unexpectedly"

    and how to get rid of it.

    I appreciate any help.
    Last edited by tesicg; December 7th, 2012 at 02:30 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center