TechBubbles

WCF Discovery with UDP

Inorder to call the WindowsCommunicationFoundation service, a port or pipe which assigned to the service must be available and the client must know the address endpoints before calling the services.

If the service could use any available address then client can discover that address at runtime. There is a industry standard-based solution which helps in discovering the service addresses.

Address Discovery

Discovery relies on the User Datagram Protocol(UDP). Client uses UDP to broadcast discovery requests for any end-point which supports the contract type. These requests are received by dedicated end-points. The end-points responds back to the client with service-address that support specified contract.

WCF offers a standard discovery endpoint with the type UdpDiscoveryEndpoint

Read more

Related Posts:

No comments

Web services security

Introduction

Securing a Web service is possible using WSE (Web Services Enhancements) for .NET. We can define the security requirements for both incoming and outgoing SOAP Messages this we can call it is a policy.

We can define the policy in two ways

1. Using WSE Settings 3.0 Tool

2. Adding the policy element to the XML file

Alternatively we can define the policy file either in development or deployment environment. It is more easy for an administrator to define a policy for an application when it is deployed using policy file.

Related Posts:

1 comment

MTOM Support to Web Service

Overview of MTOM

Using MTOM an application can send or receive a large amount of data. MTOM allows message-level security to be applied to the message including binary data. MTOM encodes the SOAP message and transmits the message as XML.

Following is the procedure to send large amount of data using MTOM

  1. Open the web service project in Visual studio 2005

  2.   Enable the project to use WSE by

        a. In solution explorer right click the project and then click WSE Settings

        b. Select the general tab

        c. Select Enable this project for Web Services Enhancements and 

           Enable Microsoft Web Services Enhancements SOAP Protocol 

           Factory.

3. Specify that web service can accept SOAP messages encoded using MTOM.

        a. In solution explorer right click the project and then click  WSE Settings.

        b. Select the Messaging tab.

        c. Choose optional or always for the Server Mode.

           always MTOM mode specifies that all incoming and outgoing SOAP  

           messages must be MTOM encoded.

           optional MTOM mode specifies that whether or not all incoming and  

           outgoing messages can be encoded.

Define a Web service method that returns a byte array.

[WebMethod]
public byte[] GetFile(string fileName)

{

    byte[] response;
    String filePath = AppDomain.CurrentDomain.BaseDirectory 
+ @"App_Data\" + fileName;
    response = File.ReadAllBytes(filePath);
    return response;

}

4. Configure the Web server to handle the larger amount of data.

<configuration>
  <system.web>
  <httpRuntime maxMessageLength="409600"
    executionTimeoutInSeconds="300"/>
  </system.web>
</configuration>

Related Posts:

3 comments

Digital Signing the SOAP Message

WSE allows you to digitally sign a SOAP Messages by overriding the SecureMessage method.

To sign a SOAP message

1. The following code example overrides the SecureMessage method.

public override void SecureMessage(SoapEnvelope envelope, Security security)
{

//Obtain the security token with which you want to sign the SOAP message with.

KerberosToken kerbToken = new 
KerberosToken("host/" + hostname + "@" + domainName);
// Add the security token.
security.Tokens.Add(kerbToken);
// Specify the security token to sign the message with.
MessageSignature sig = new MessageSignature(kerbToken);
// Add the digital signature to the SOAP message.
security.Elements.Add(sig);

  }

Related Posts:

2 comments

Adding Security Credentials to SOAP

The WSE 3.0 for .NET enables the developers for creating one or more security credentials that can be added to the SOAP Message.

The following procedure describes how to add one or more security credentials to a SOAP Message.A computer must be configured to accept the SOAP Messages embedded with the security credentials.

Two types of security credentials that can be setup for the computer

  1. X.509 certificate.
  2. Username and Password.

You can configure the computer for X.509 certificate by reading the  SOAP Messages signed by an X.509 Certificate.

You can also configure the computer for Username Token by validating SOAP Messages signed by Username Token.

Following procedure is To Add a security token to SOAP

1.  Open the Web Service Client project

2.Add references to the Microsoft.Web.Services3 and System.Web.Services assemblies. 

3. Add a Web Reference to the Web service that is to receive the SOAP message signed with the UsernameToken.

4. Add the folllowing user directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography.X509Certificates;

using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Design;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;

 5. Write the following code by overriding the SecureMessage Method  in web  service.

public override void SecureMessage(SoapEnvelope envelope, Security security)
{
UsernameToken userToken;
userToken = new UsernameToken(userName, userPasswordEquivalent,
    PasswordOption.SendNone);
// Adds the token to the SOAP header.
security.Tokens.Add(userToken);
}

Related Posts:

2 comments

Verify SOAP Messages Signed using Username and Password

To validate digital signatures for incoming SOAP Messages created using Username Token, WSE Must be configured.

The following procedure explains how to configure a WSE to validate digital signatures created using Username Token.

1. Start Visual studio 2005

2. File Menu, New then click Project.

3. Select ASP.NET Web Service in  the templates pane.

4. Add a reference to the Microsoft.Web.Services3 assembly.

5. In the Web.config file include the <SoapServerProtocolFactory> element in <webServices> section.

<configuration>
   <system.web>
        <webServices>
            <soapServerProtocolFactory 
type="Microsoft.Web.Services3.WseProtocolFactory,
 Microsoft.Web.Services3,
 Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </webServices>
    </system.web>
   </system.web>
</configuration>

  Write the following code to validate the SOAP Message

Read more

Related Posts:

2 comments

SOAP Fundamentals

Introduction

SOAP is  a protocol to exchange the XML messages over the network using HTTP\HTTPS.It stands for Simple Object Access Protocol.It is platform and language independent.

SOAP Building Blocks

A SOAP Message is an XML Document contains the following elements

  • Envelope element which identifies the XML document as a SOAP Message.It is required element in SOAP message.
  • Header element which contains the header information which is an optional element.
  • Body element contains the request and response information which is a required element in SOAP.
  • Fault element contains the error information during the processing of a message.

SOAP Message Syntax

<?xml version="1.0"?><soap:Envelope//Must contain SOAP envelope namespace 
xmlns:soap=http://www.w3.org/2001/12/soap-envelope 
//Must use SOAP encoding namepace
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  <soap:Header>  </soap:Header>
  <soap:Body>  <soap:Fault>  </soap:Fault>  </soap:Body>
</soap:Envelope>

Read more

Related Posts:

1 comment