Web Service SOAP Header

Using VB.

I have added a web reference to my project for a web service using the specified http WSDL.

I have added an instance of the service to my page:

Dim ws As New myservice

One of the requirements is that I use header authentication in the SOAP response (username and password). What is the best way to approach this.

I do not see any reference to header elements in the WSDL but here is a sample of the SOAP request required. Also I don't see any reference to a class for this type of authentication.


<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><wsse:UsernameToken xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">

<wsse:Username xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext"></wsse:Username>

<wsse:Password xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext"></wsse:Password>




Thanks very much in advance for any suggestions.

11/7/2007 8:34:44 PM
asp.net.xml-web-services 7071 articles. 0 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 3

Your web service needs to include a class that inherits from the SoapHeader class and contains a username and password property, as well as an authentication method that can verify these credentials with your database.  When you instantiate an instance of your web service, you also need to instantiate an instance of the server's authenticationheader class.  You then fill the authenticationheader's login properties and then pass the whole object to your service's header property.  You can then call your own web methods, in which you first use the credential properties in the header object to first verify the user.  This is the high-level view.  If I can find the sample code I used I will post it.


11/8/2007 2:40:54 AM

Thank you very much for your reply. Any sample code would be very helpful as I am new to this. This is a VB application.

Here is what I have so far on a page where I want to call this particular web service.

Imports Microsoft.Web.Services3

Imports Microsoft.Web.Services3.Security

Imports Microsoft.Web.Services3.Security.Tokens

Then, for the event of calling the service:

Dim userToken As New UsernameToken("myusername", "mypassword")

Dim ws As New mywebservice           (web reference already added)



I know what I have is incomplete but I found the userToken sample from another Microsoft example. I was hoping that I am on the right track since the sample SOAP header I have for this service should look like the following: I am noticing the use of UsernameToken


<payloadManifest xmlns="http://www.starstandards.org/webservices/2005/10/transport">

<manifest contentID="Content0" namespaceURI="http://www.starstandards.org/STAR" element="ProcessPartsOrder" version="2.01"/>


<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

<wsse:UsernameToken xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">

<wsse:Username xmlns:wsse="%20myusername%20http://schemas.xmlsoap.org/ws/2003/06/secext"> myusername </wsse:Username

<wsse:Password xmlns:wsse="%20mypassword%20http://schemas.xmlsoap.org/ws/2003/06/secext"> mypassword </wsse:Password>





11/8/2007 12:57:03 PM

I'm not actually using Security.Tokens in my app, but what you have looks pretty good to me.

11/8/2007 4:44:18 PM


Did you ever manage to get this to work ? I am having exactly the same problem as you but I gave up using the tokens and have now tried generating the SOAP message which is all dandy until i try get a response and it fails everytime, would be interested to know how you solved your problem as mine seemed pretty similiar, my code is something like this.

 System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(http://mywebservice);

string strSOAPRequestBody = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>" +

"<soapenv:Header>" +

"<wsse:Security>" +

"<wsse:UsernameToken>" +

"<wsse:Username>username</wsse:Username>" +

"<wsse:Password>password</wsse:Password>" +

"</wsse:UsernameToken>" +

"</wsse:Security>" +

"</soapenv:Header>" +

"<soapenv:Body>" +

"</soapenv:Body>" +"</soapenv:Envelope>";

request.Method = "POST";

request.ContentType = "application/soap+xml; charset=utf-8";

request.ContentLength = strSOAPRequestBody.Length;

StreamWriter streamWriter =new System.IO.StreamWriter(request.GetRequestStream());



StreamReader streamReader =new System.IO.StreamReader(



string strResponse = "";while (!streamReader.EndOfStream)

strResponse += streamReader.ReadLine();


11/9/2007 5:29:54 PM

You also need to set the policy for the client. Here is an article that details this out: http://msdn2.microsoft.com/en-us/library/aa528807.aspx.

My sample code (in C#) is as follows:

1    using Microsoft.Web.Services3.Security.Tokens;
2    using Microsoft.Web.Services3.Design;
5    public partial class Form1 : Form
6    {
8            private void Button1_Click(object sender, EventArgs e)
9            {
10                   SomeWebService.SomeService serviceClient = new SomeWebService.SomeService();
11                   serviceClient.SetClientCredential(new UsernameToken("userName", "password", PasswordOption.SendPlainText));
12                   serviceClient.SetPolicy(new Policy(new UsernameOverTransportAssertion()));
14                   // .... do other things
16                   serviceClient.SomeCall();
17           }
19   }

 Hope this helps.


12/8/2007 3:32:45 PM

I think you mean in the SOAP Request, not the response.

This is the ws-security spec, you can do it using WSE which is covered nicely by Scott Mitchell here:



[C# MVP]
12/8/2007 3:45:28 PM

Similar Artilces:

How to call a .net web service from another .net web service?
Hi all,I have developed two asp .net web services using visual studio .net 2003.I wish to call one web service from another web service.I tried adding a web reference of the web service in another web service and was able to do so.but i m not able to access the web methods provided by the web servicecould you please suggest a way to go about itExpecting quick replyThanxCharmy try to make sure that you reference it in the web reference and call it properly this is sample  [WebMethod()] public double CalcDistance(int x1, int y1, int x2, int y2) { Calculator.Service1 calc = new...

xml web service --uploading the file to the xml web service
how can we upload the file in the xml web service 1.i mean what will be the return value in the proxy class 2.and how am i going to send the file to the xml web service----regards Bipul Kumar Here are some links to articles that helped us get this done: http://msdn.microsoft.com/webservices http://www.microsoft.com/downloads/details.aspx?familyid=06255a94-2635-4d29-a90c-28b282993a41&displaylang=en https://www.sys-con.com/dotnet/article.cfm?id=458 Hope this helps....

Web service in .NET from Java Web Service
Hi there,I'm pretty new to .net (although i have years of experience with the old vb 6, access 2k, as well as java)... and need some with perhaps either some syntax or something.Here is the wsdl.<wsdl:definitions targetNamespace="http://www.dynix.com/schema/book">−<wsdl:types>−<schema targetNamespace="GetBookInfoByISBN">−<complexType name="BookInfoType">−<sequence><element maxOccurs="1" minOccurs="0" name="Title" nillable="true" type="xsd:string"/><element maxOccurs=&quo...

.NET web services Vs Java Web Services
Hello, does anyone know of a book or good source of information that compares .NET and Java Web Services? (I would like soemthing neutral if possible). I am thinking of approaching this subject for my dissertation? Many Thanks Rob Hi Rob, Last year I had to give a powepoint presentation on Web Services. I noticed some good books at barnes and noble that discussed the subject. These books were specific to Java and discussed Web Services in a very clear fashion. They gave some elementary examples that were easy to understand. I have not yet had the pleasure of creatin .NET Web Servi...

web service SOAP Headers
If this isn't the right forum, let me know what is.Is there a difference between SOAP serialization and  and XML serialization.I have been reading heavily and am now quite confused.I understand that SOAP serialization produces XML, but perhaps without a specific schema or a scheme very different from XML. In the context of web services, the XML Serializer is used to produce XML in SOAP format. What you may be getting confused about is that there is also a "runtime serialization" subsystem. This can serialize data either using a Binary Formatter, or a SOAP Formatter. It...

SOAP Web Service Problem (problema con un web service)
Please help, I can't read a webservice method (webmethod) from asmx web service, with Delphi firemonkey, In my first try I put a WDSL Importer, and I can retrive data from simplex type (string, booleans, integers) but when the method returns a DataSet, i loose my way. Por favor, ayuda, no puedo leer datos de un web service si el metodo que regresa es un DataSet, el web service esta hecho en dot.net así que es un asmx, utilizando el WDSL importes, traje datos sencillos como enteros, boleanos y otros, pero en el caso de arreglos como un DataSet no lo he conseguido, estoy perdido, y l...

what are web services and what are the advantages of web services?
 Hello  i am new to this .net stuff and i was ask on the job interview what a web services is?and if i did not know given that i had a project ( as a project manager,  or a web developer)   what  is it? how do i start a >NET project on it? what are the main advantages is?  HOW DO I START THIS IN THE INTERVIEW>  and what basic books do i buy?   Hi There, There plenty of source on the net about webservice Definiton: http://en.wikipedia.org/wiki/Web_service http://www.codeproject.com/Purgatory/Defining_Web_Services.asp...

Is web services a part of web Service?
  I have a question: Is web services a part of web server?? And when the client calls web service, it means that client calls web server?? Or is it a different entity in itself which communicates separately both with client and server and acts as middleware application.. I am very confused.. Can someone explain me the architecture...??? Thanks..Dont forget to click "Mark as Answer" on the post that helped you.This credits the member,earns you a point & marks your thread as Resolved so that new users will know where to search for their queries. When you build and dep...

Calling a Web Service from a Web Service
Hello,I was looking for some feedback on calling a web service from within a web service. I've heard that it's not good practice (or not possible). I have a scenario where I think it might make some sense.Within our infrastructure, we've created a web service that handles incoming updates on the statuses of all processes. This has proven to be a good thing since it allows applications to communicate across server to make status updates. It's also used by third party developers and applications to communicate with our infrastructure.Along these lines ... we are planning to create a new compon...

Web Site Project: How to configure web service URL in web.config (web service defined in a referenced DLL)
I have a web site that references a business logic DLL project. In the business logic project, there is a web service defined in its app.config file something like this: <applicationSettings>  <MyNamespace.BLL.Properties.Settings>    <setting name="MyNamespace_BLL_MyServer_ServiceName" serializeAs="String">    <value>http://blah.blah.blah.asmx</value>  </setting>  </MyNamespace.BLL.Properties.Settings></applicationSettings> When the web site is published, the web ...

create valid xml to send to web service based on the schema provided by web service
Problem: I have a web page which is being populated from a dataset containing multiple tables.  I now need to call a web service and send the majority of this data to be incorporate into a mainframe system.  I have been supplied with the schema that the web service will be using to validate the data.  I am new to web services and I am not sure how to take my existing dataset and transform it into an xml document that matches the schema I was provided with. There is a main schema with an element which is a custom complex type.  This custom type consists of an element whi...

Best Practice for .Net Web Service access to a Web Service on a Test and Production Servers
Hello All, What is the best way to control a .Net web service to be able to access a remote server for testing and then point to another remote server to access the web service in production? Do I need to generate and maintain 2 different proxy objects? TIA, Bob Bob // first create the proxy if not isvalid( i_service) then i_service = create fundtraderproxy_TradeServicesClient_BasicHttpBinding_ITradeServices end if ///You'll see code something like this in the constructor of your proxy //dynamically set the endpoint url with the user supplied value - //r...

What action by a web service requires an app to update their web reference to a Web Service
I create a web reference to a web service in my aspx web application which returns an XML object. If the owner of the web service makes a change to their object am I required to do an update web reference? What if I dont use the information from the new object? thanks Larry You should make the change only if the contract b/w the two has changed (e.g. parameters, return values), etc.-Mathew Nolton Website=www.cybral.com Email=mnolton@cybral.com Blog=weblogs.asp.net/mnolton If the web service now returns a new element and my class reference doesn't match their new class ref...

New to web services, why does PB10 web service proxy wizard say there are no services?
here... http://webservices.amazon.com/AWSECommerceService/205-10-05/AWSECommerceService.wsdl oops typo... still doesn't show any services though... http://webservices.amazon.com/AWSECommerceService/2005-10-05/AWSECommerceService.wsdl "Chance" <chance@booklog.com> wrote in message news:43b44cb3$1@forums-1-dub... > here... > > http://webservices.amazon.com/AWSECommerceService/205-10-05/AWSECommerceService.wsdl > Upgraded to 10.2x and now seems to be working...at least it created the proxy. "Chance" <chance@booklog.co...

Web Service invoking another Web Service
hello, I have a web service and I have to consume another web method of some other web service. I have to do everything through code. [I cannot use "Add Web Reference" utility in the VS.NET]. I am using C# for coding the web service. Thanks in advance. Phanikum Yep, You could do that! Basically you have to use WSDL.exe http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfWebServicesDescriptionLanguageToolWsdlexe.asp Once you have proxyclass in a file from WSDL.EXE, make an assembly and use that in your app! Sreedharhtt...

Web resources about - Web Service SOAP Header - asp.net.xml-web-services

United States Department of Health and Human Services - Wikipedia, the free encyclopedia
The United States Department of Health and Human Services ( HHS ) is a Cabinet department of the United States government with the goal of protecting ...

In the end the Beatles finally come to streaming services
It's been a long and winding road to get the Beatles on your devices and streaming services, but you've finally reached your destination and ...

The Beatles arrive on 9 different streaming music services
... December 24th in every time zone around the world, a huge portion of The Beatles' catalog will be available to stream on nine different services. ...

New online service seeks to shake up Seattle's office leasing market
... tools, such as a new one called Crelow. The Minneapolis-based startup, which launched in Seattle Wednesday, bills itself as matchmaking service ...

The Beatles discography will be on streaming services as of Christmas Eve
... any music fan can get excited about. As of 12:01 AM local time on Christmas Eve, The Beatles' entire discography will be on streaming services ...

How video streaming services are changing the future of TV
... created, distributed, and monetized. This shift has been brought on by the rising popularity of over-the-top content and video streaming services. ...

America mourns service members killed in Afghanistan
One mother who runs a Washington restaurant posted a note on the door that said they were closed to "mourn this terrible loss"

Favorite apps and services of 2015
Save time and money with our Windows editor's favorites: Android Pay, Google Fi, PlayStation Vue, and Windows 10.

College Financial Service Provider Higher One To Pay $28M In Fines, Refunds For Misleading Students
Higher One, Inc. promises to help students reach their goal of achieving a degree by providing money management and refund services. But federal ...

Taiwan market: Taiwan Secom provides retail management services via cooperation with Microsoft
Taiwan Secom, the largest residential/commercial security service provider in Taiwan, on December announced cooperation with Microsoft to provide ...

Resources last updated: 12/24/2015 12:56:53 AM