'3. Implementation/WCF'에 해당되는 글 12건

  1. 2015.02.02 Sharing session state over multiple services using StateServer
  2. 2014.12.14 Routing with WCF
  3. 2014.11.19 WCF Routing with Failover and Load Balancing
  4. 2014.10.11 Address filter mismatch
  5. 2014.08.12 Load Tests for WCF Services
  6. 2014.05.24 PollingDuplex multiple mode timeouts demystified
  7. 2014.05.24 WCF Configuration Schema (web.config)
  8. 2014.05.20 WCF Tracing and Message Logging
  9. 2014.04.29 upload and download over 30 MB file between silverlight and wcf service
  10. 2013.12.05 HTTP Session sharing between WCF services
  11. 2013.12.05 A Simple Duplex Service in WCF
  12. 2013.06.28 Choosing a Binding
2015. 2. 2. 23:51

Sharing session state over multiple services using StateServer

For about a week I went through how to share session state over multiple services because our customers wanted to make their service to become HA (High availability). To construct our service as HA, sharing session state over multiple WAS was very important. And because we're using MySQL, using StateServer instead of SqlServer was unavoidable option.


It was really hard to find any document related to this knowledge. Finally I found very helpful site which gives simple solution to us. 


http://weblogs.asp.net/lichen/sharing-session-state-over-multiple-asp-net-applications-with-asp-net-state-server


Thanks to Li Chen. In addition to the link, I made sample project to show this. Here it is.



StateSeverTest.zip



To run this example, you have to start "ASP.NET State Service" as below:


1. Type Windows + R and type the "services.msc"


2. Find the "ASP.NET State Service"





3. Start that service


That's it. 


Updated at 2015.02.02


In case of WCF, to share session between difference wcf services routed by wcf routing, you should set SoapProcessingEnabled option to false. (Thanks to my smart colleague, Mr. Oh)


Refer the following for more information:


https://msdn.microsoft.com/en-us/library/ee816917(v=vs.110).aspx


2014. 12. 14. 16:56

Routing with WCF


Here is sample code for routing with WCF.



WCFRoutingServiceTest.zip







Web.config for service 


<?xml version="1.0"?>


<!--

  For more information on how to configure your ASP.NET application, please visit

  http://go.microsoft.com/fwlink/?LinkId=169433

  -->


<configuration>

  <system.web>

    <compilation debug="true" targetFramework="4.0" >

      <assemblies>

        <add assembly="System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

      </assemblies>

    </compilation>

  </system.web>

  <system.serviceModel>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">

      <serviceActivations>

        <add relativeAddress="RiskManagementServiceUAT.svc" service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      </serviceActivations>

    </serviceHostingEnvironment>

    <services>

      <!--ROUTING SERVICE -->

      <service name="System.ServiceModel.Routing.RoutingService" behaviorConfiguration="routerConfig">

        <endpoint address=""

                  binding="basicHttpBinding"

                  contract="System.ServiceModel.Routing.IRequestReplyRouter"

                  name="reqReplyEndpoint" />

      </service>

    </services>


    <routing>

      <filters>

        <filter name="matchAll" filterType="MatchAll" />

      </filters>


      <filterTables>

        <filterTable name="routingTable">

          <add filterName="matchAll" endpointName="RiskService" backupList="RiskServiceBackup" />

        </filterTable>

      </filterTables>

      <backupLists>

        <backupList name="RiskServiceBackup">

          <add endpointName="RiskService2"/>

        </backupList>

      </backupLists>

    </routing>


    <behaviors>

      <serviceBehaviors>

        <behavior name="routerConfig">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

          <routing routeOnHeadersOnly="false" filterTableName="routingTable" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <client>

      <!-- Define the client endpoint(s) to route messages to -->

      <endpoint name="RiskService"

            address="http://localhost:81/Service1.svc"

            binding="basicHttpBinding"

            contract="*" />

      <endpoint name="RiskService2"

            address="http://localhost:82/Service1.svc"

            binding="basicHttpBinding"

            contract="*" />

    </client>

  </system.serviceModel>

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>

</configuration>



client.config for silverlight client  


<configuration>

    <system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"

                    maxReceivedMessageSize="2147483647">

                    <security mode="None" />

                </binding>

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="http://localhost/RiskManagementServiceUAT.svc" binding="basicHttpBinding"

                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"

                name="BasicHttpBinding_IService1" />

        </client>

    </system.serviceModel>

</configuration> 


* I updated source to make someone to understand better.



WCFRoutingServiceTest_updated.zip



* Address filter decides where to go using client's ip address. Like the sticky session under L4 load balancer, address filter ensures client to be directed to same was.



WCFRoutingServiceTest_addressfilter.zip



References:


2014. 11. 19. 23:24

WCF Routing with Failover and Load Balancing

The following sample shows how to support failover and load balancing using WCF Routing.






WCFRoutingServiceTest_LB.zip


Sorry, but web.config has an error. Same service was specified as backup list so this causes to round robin routing to fail. Fix this problem by yourself.


References : http://www.codeproject.com/Articles/778575/WCF-Routing-Service-Part-III-Failover-Load-Balanci

2014. 10. 11. 08:36

Address filter mismatch

After setting the URL Rewriter on IIS I got the following error from WCF services which were set as  polling duplex or net.tcp protocols.



 The message with To 'http://localhost/WCFService.svc' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.



The reason is that by default, WCF ensures that the To of each Message matches the intended address.


It's simple to resolve this. Set the AddressFilterMode as Any!


[ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]


Here's sample code:



    [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2)
        {
            return n1 + n2;
        }

        public double Subtract(double n1, double n2)
        {
            return n1 - n2;
        }

        public double Multiply(double n1, double n2)
        {
            return n1 * n2;
        }

        public double Divide(double n1, double n2)
        {
            return n1 / n2;
        }
    }

References:

http://msdn.microsoft.com/en-us/library/system.servicemodel.addressfiltermode(v=vs.110).aspx 

https://social.msdn.microsoft.com/Forums/vstudio/en-US/b5ae495b-f5fb-4eed-ae21-2b2280d4fec3/address-filter-mismatch-wcf-addressing




2014. 8. 12. 23:31

Load Tests for WCF Services

Refer following links:


Generating Load Tests for WCF Services with the WCF Load Test Tool


http://blogs.msdn.com/b/mcsuksoldev/archive/2010/12/03/generating-load-tests-for-wcf-services-with-the-wcf-load-test-tool.aspx


Create and run a load test


http://msdn.microsoft.com/en-us/library/ms182594.aspx

2014. 5. 24. 08:36

PollingDuplex multiple mode timeouts demystified

Source: http://blogs.msdn.com/b/silverlightws/archive/2010/07/16/pollingduplex-multiple-mode-timeouts-demystified.aspx


Written by   



The new MultipleMessagesPerPoll mode added to PollingDuplex in Silverlight 4, comes with some new timeouts , so I thought it would be useful to post a detailed description of how those work. Unfortunately this is not currently covered by our documentation, which is something we are looking to address in upcoming documentation refreshes.

This is a fairly advanced topic, and the default settings should work well for most customers, so only modify these if you are encountering an issue, and you are fairly confident a timeout is causing the problem. The information below applies only to the new multiple messages mode, which is activated by settingduplexMode="MultipleMessagesPerPoll" on the PollingDuplex binding or binding element.

One important thing in the text below is to differentiate between infrastructure messages (such as polls in this case) and application messages. Infrastructure messages such as polls (and poll responses) are not initiated by or surfaced to the user – they are just an implementation detail of the protocol. Application messages are messages that actually originated in the user code. They can be separated into client-to-server messages (“requests coming from client”) or server-to-client messages (“server responses to requests coming from client” and “requests coming from server”). There is no “client responses coming from server” because of the way polling works. I will try to stick to this terminology in the text below.

Most of the new timeouts live on the server. All class and member names refer to the server-side System.ServiceModel.PollingDuplex.dll that ships in the “Server” folder of the Silverlight SDK. Take a look at the following diagram for a visual explanation:




The diagram shows an incoming poll and the chunked response being returned containing application messages. The first server-to-client application message is greater than 16/32KB (16 for self-hosted PollingDuplex services, 32KB for IIS-hosted), so the chunked response is flushed and the message should arrive immediately at the client. The then client sends a smaller application messages, but the total size does not reach 16/32KB, so the chunked response is not flushed. To prevent the message from getting stuck, the chunked response will be flushed and closed when the MaxOutputDelay timer expires, and the message will then be delivered to the client. Then the client sends two application messages coming in from the client and the timeouts associated with those.

Here is a more detailed description of each timeout.

ServerPollTimeout

  • Set it here
    • System.ServiceModel.PollingDuplexHttpBinding.ServerPollTimeout
    • System.ServiceModel.Channels.PollingDuplexBindingElement.ServerPollTimeout
  • Definition: Time the server holds the poll request prior to sending an empty poll response to the client. After the first outgoing server-to-client application message (either server response to request coming from client or request coming from the server) gets sent, this timer stops being used, andMaxOutputDelay kicks in. Bound to the client dispatcher (HTTP request / response)
  • Default: 15 s

MaxOutputDelay

  • Set it here
    • System.ServiceModel.PollingDuplexHttpBinding.MaxOutputDelay
    • System.ServiceModel.Channels.PollingDuplexBindingElement.MaxOutputDelay
  • Definition: Time between the last outgoing server-to-client application message and the HTTP response being closed; it’s reset with each new outgoing message being dequeued. Closing the response ensures that all messages are flushed and no message will take longer than MaxOutputDelay to be delivered to the client. Bound to the client dispatcher.
  • Default: 200 ms

PollHeartbeatTimeout

  • Not settable – this is an internal property
  • Definition: Timer which is started when a poll response is sent to the client, and stopped when the next poll for that dispatcher is received. Bound to the client dispatcher. If the timeout is reached, all the channels bound to the dispatcher are faulted. This is how we determine if a client “is still there”.
  • Value: 4 * ServerPollTimeout + 30 s (after polling has started), 2 * ServerPollTimeout + 15 s (if server has not received the first poll from the client)

InactivityTimeout

  • Set it here
    • System.ServiceModel.PollingDuplexHttpBinding.InactivityTimeout
    • System.ServiceModel.Channels.PollingDuplexBindingElement.InactivityTimeout
  • Definition: Timer which is reset when an application messages is received by the channel. If the timeout is reached, the channel is faulted. Bound to the client session. Note that this not affected by polls, contrary to the way this same timeout behaves with infrastructure messages on other bindings (as described here). So effectively this is the same as ReceiveTimeout.
  • Default: 10 min

ReceiveTimeout

  • Set it here
    • System.ServiceModel.Channels.Binding.ReceiveTimeout
  • Definition: Timer which is reset when the ServiceModel layer pumps an application message from a PollingDuplex channel. If the timeout is reached, the channel is aborted. Infrastructure messages such as polls don’t affect this timeout. Bound to the client session (channel).
  • Default: 10 min

 

On the client side, we also have some timeouts that may be of interest. All class and member names below refer to the client-side System.ServiceModel.PollingDuplex.dll that ships in the “Client” folder of the Silverlight SDK.

ClientPollTimeout

InactivityTimeout

Hope this is useful.

2014. 5. 24. 07:30

WCF Configuration Schema (web.config)


The following link shows the detailed information about wcf web.config configuration. 


http://msdn.microsoft.com/en-us/library/ms731734(v=vs.110).aspx






The tip to search for msdn site, use "site:" option on Google.


site:http://msdn.microsoft.com/en-us wcf "<bind>" 



Additionally silverlight configuration schema site is as below:


http://msdn.microsoft.com/ko-kr/library/dd547083(v=vs.95).aspx

2014. 5. 20. 05:56

WCF Tracing and Message Logging

Really I did ridiculous thing. 


Our system showed "Server too busy" exception so I wanted to trace the log messages of the WCF services. I followed lots of instructions for that. 



And the critical thing was as below:


  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="C:\logs\Traces.svclog" />
  </sharedListeners>


After restarting our service, I refreshed the windows explorer to check if the log file was created but it didn't. 


The reason was very simple. The log file couldn't be created if the destination folder does not exist. So only after creating the 'c:\logs' folder, my concern was removed.



MSDN offers the recommended settings for tracing and message logging

(http://msdn.microsoft.com/en-us/library/aa702726(v=vs.110).aspx)



  • Recommnded Settings for a Production Environment

<configuration>
 <system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Warning"
            propagateActivity="true" >
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="myUserTraceSource"
            switchValue="Warning, ActivityTracing">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="C:\logs\Traces.svclog" />
  </sharedListeners>
 </system.diagnostics>

<system.serviceModel>
  <diagnostics wmiProviderEnabled="true">
  </diagnostics>
 </system.serviceModel>
</configuration>

  • Recommended Settings for Deployment or Debugging
configuration>
 <system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Information, ActivityTracing"
            propagateActivity="true" >
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="myUserTraceSource"
            switchValue="Information, ActivityTracing">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="C:\logs\Traces.svclog" />
  </sharedListeners>
 </system.diagnostics>

 <system.serviceModel>
  <diagnostics wmiProviderEnabled="true">
      <messageLogging 
           logEntireMessage="true" 
           logMalformedMessages="true"
           logMessagesAtServiceLevel="true" 
           logMessagesAtTransportLevel="true"
           maxMessagesToLog="3000" 
       />
  </diagnostics>
 </system.serviceModel>
</configuration>

To see the logs, use the service trace viewer tool!
(C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\SvcTraceViewer.exe)

(http://msdn.microsoft.com/en-us/library/ms732023(v=vs.110).aspx)



2014. 4. 29. 02:39

upload and download over 30 MB file between silverlight and wcf service

Recently My project members and I are suffering from the problem that cannot upload and download over 30 MB file between silverlight and wcf service.


I googled lots of things and applied the suggestions but anything did not resolve our issue.


With this trouble remained I cannot sleep well so I'm writing this article now.


I searched more webs to find any hint to help us. Following sites can be helpful but the result will be known tomorrow.


http://ajaxuploader.com/large-file-upload-iis-debug.htm


This site suggests very good guide lines as below: 


1. Required

IIS7 - maxAllowedContentLength

IIS6 - maxRequestLength


2. Microsoft URL Scan

C:\WINDOWS\system32\inetsrv\urlscan\UrlScan.ini

MaxAllowedContentLength


3. File upload debug file


debug-upload.zip



http://ajaxuploader.com/large-file-upload-iis-asp-net.htm


This sites shows the required configuration for IIS7


1. Modify the maxAllowedContentLength setting in the web.config


<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
  </security>

</system.webServer> 


=> 2147483648 - 2 GB in size

2. Edit the request filtering feature settings and the request limits using IIS manager

  • Open IIS Manager.
  • Select the website that you want to configure.
  • Make sure you are in Features View per the button at the bottom of the manager.
  • Select Requests Filtering and open it by double-clicking the icon. The Request Filtering pane displays.
  • From the Actions pane on the right hand side of the screen click Edit Feature Settings... link. The Edit Request Filtering Settings window displays.
  • In the Request Limits section, enter the appropriate Maximum allowed content length (Bytes) and then click the OK button.
  • Restart IIS.


3. Manually edit the ApplicationHost.config file



  • Click Start. In the Start Search box, type Notepad. Right-click Notepad, and then click Run as administrator.
  • On the File menu, click Open. In the File name box, type %windir%\system32\inetsrv\config\applicationhost.config, and then click Open.
  • In the ApplicationHost.config file, locate the <requestLimits> node.
  • Remove the maxAllowedContentLength property. Or, add a value that matches the size of the Content-Length header that the client sends as part of the request. By default, the value of the maxAllowedContentLength property is 30000000. 

    For example, modify the following configuration data inside the <requestFiltering> section.

    <requestLimits maxAllowedContentLength ="<length>" />
  • Save the ApplicationHost.config file.


Finally to resolve this, we developed upload/download feature with new way: duplex communication on download and upload partitioning.


But this information is worth keeping in mind.

2013. 12. 5. 06:43

HTTP Session sharing between WCF services

My project developers said that http session sharing between wcf services is not easy,

they were considering another way to do that such as session server.


but I didn't agree their saying, I believed that Microsoft never leave this kind of critical issue be alive. So at dawn I wrote sample project and finally I solved that. 


Maybe this issue was caused by out mistake when creating a wcf service project.


Here is the sample solution:



WcfSessionTest.zip






2013. 12. 5. 06:26

A Simple Duplex Service in WCF

WCF 를 이용해서 양방향 통신할 때 참고할만한 예제


Source: http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/a-simple-duplex-service-in-wcf/



WcfService3.zip





2013. 6. 28. 21:57

Choosing a Binding



From "Programming WCF Services" book