Brockmann: "Creating Rich Web
Applications Gets a Ton Easier"

e-grou chooses Visual WebGui
over standard ASP.NET

Quick migration of VB 6.0
Applications to the Web

Fully functional software versions
for 30 days evaluation period

Download the free edition of the
Visual WebGui Studio
 

Code Snippets

posted on June 24, 2009 :: 596 views

Hello everyone:

I hope this help for anyone who trying to work with WCF web services.

When you need to use web services, you have problems to configure it. Why? because the default configuration generate code for wsHttpBinding and not for a basicHttpBinding.

The difference is the authentication type.
wsHttpBinding works on "windows authentication" and the basicHttpBinding works on "forms authentication".

Due to this, I have prepared the examples of the web.config file for the server and for the client.

1.- For the server side (web service hosted on a sub domain) on the web.config, you need to establish <authentication mode="Forms" /> and the next part:

<system.serviceModel>
    <serviceHostingEnvironment>
       <baseAddressPrefixFilters>
          <add prefix="http://services.mydomain.com.mx" />
       </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    <services>
       <service name="svcRef.Service" behaviorConfiguration="ServiceBehavior">
          <endpoint address="http://services.mydomain.com.mx/Service.svc" binding="basicHttpBinding" contract="svcRef.IService" >
             <identity>
                <dns value="http://services.mydomain.com.mx"/>
             </identity>
          </endpoint>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
    </services>
    <behaviors>
       <serviceBehaviors>
          <behavior name="ServiceBehavior">
             <serviceMetadata httpGetEnabled="true"/>
             <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior>
       </serviceBehaviors>
    </behaviors>
</system.serviceModel>

IMPORTANT NOTES: you need to change the binding type to "basicHttpBinding" and the identity of the endpoint to <dns value="http://services.mydomain.com.mx"/>

2.- For the client side on the web.config you need these part:
<system.serviceModel>
    <bindings>
       <basicHttpBinding>
          <binding name="Servicios" 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://services.mydomain.com.mx/Service.svc" binding="basicHttpBinding"
         bindingConfiguration="Servicios" contract="svcRef.IService" name="Servicios" >
         <identity>
            <userPrincipalName value="SERVER\mydomain.co_web" />
         </identity>
       </endpoint>
    </client>
</system.serviceModel>

IMPORTANT NOTES: You need the same binding type to "basicHttpBinding" in the endpoint. The bindings service model change to basicHttpBinding. You may obtain the user <userPrincipalName value="SERVER\mydomain.co_web" /> running th svcutil. for example: c:\program files\microsoft sdks\windows\v6.0A\bin\svcutil http://service.mydomain.com.mx/Service.svc?wsdl /language:VB these line generate 2 files, output.config and service.vb. In the output.config you can find the user.

The difference between basicHttpBinding and wsHttpBinding is the authentication: on first type you pass the user name <userPrincipalNamevalue = "SERVER\mydomain.co_web" /> to the service and you don't need any more authentication, and on wsHttpBinding you need to do an authentication via windows and domain. If you try to wsHttpBinding type you have multiple errors like (405) Method not allowed by the service and "caller was not authenticated by the service"

Thanks

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.
Most promising startups
Top 3 most promising startups in 2009
   AJAX Framework | Web Development | Cloud applications | RIA Development | Silverlight Applications | Legacy Migration
The most popular open source Ajax applications framework for enterprises | Sitemap | Terms Of Use | Privacy Statement
Copyright © 2005-2009 Visual WebGui®    Design By: Template World
   
Visual Studio Partners