I've modeled it after this project:
CodeProject: WebService Authentication with UsernameToken in WSE 3.0. Free
source code and programming help:
http://www.codeproject.com/KB/cpp/WebService_Authentication.aspx?display=PrintAll
That project works perfectly fine for me. However, mine does not - I get
the error below [1] when I attempt to call the HelloWorld method in the web
service:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports Microsoft.Web.Services3
' To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
_
<Microsoft.Web.Services3.Policy("ServerPolicy")> _
<ToolboxItem(False)> _
Public Class Main
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World" &
RequestSoapContext.Current.IdentityToken.Identity.Name
'Return "WORK, DAMMIT!"
End Function
End Class
The client code:
'init web service proxy - custom generated by wsewsdl3 against the
signature of Main.asmx in the web service
Dim myserviceProxy As New WSETestingClient.Main
Dim myserviceResponse As String
'init UsernameToken, password is the reverted string of username,
the same logic in AuthenticateToken of MyUserNameTokenManager class
Dim myToken = New UsernameToken("admin", "nimda",
PasswordOption.SendPlainText)
'Set the token onto the proxy
myserviceProxy.SetClientCredential(myToken)
'Set the ClientPolicy onto the proxy
myserviceProxy.SetPolicy("ClientPolicy")
Try
myserviceResponse = myserviceProxy.HelloWorld
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString)
End Try
[1] Error:
System.Web.Services.Protocols.SoapHeaderException: Server unavailable,
please try later ---> System.ApplicationException: WSE842: The service
pipeline could not be created. --->
System.Configuration.ConfigurationErrorsException: WSE032: There was an
error loading the microsoft.web.services3 configuration section. --->
System.Configuration.ConfigurationErrorsException: WSE040: Type
MyAuthorizationLib.MyUserNameTokenManager, MyAuthorizationLib could not be
loaded. Please check the configuration file.
(D:\inetpub\wwwroot\MyTestWebService\web.config line 38) at
System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys,
SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord,
SectionRecord sectionRecord, Object parentResult) at
System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord
factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean
getLkg, Boolean getRuntimeObject, Object& result, Object&
resultRuntimeObject) at
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean
getRuntimeObject, Boolean requestIsHere, Object& result, Object&
resultRuntimeObject) at
System.Configuration.BaseConfigurationRecord.GetSection(String configKey,
Boolean getLkg, Boolean checkPermission) at
System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Web.HttpContext.GetSection(String sectionName) at
Microsoft.Web.Services3.Configuration.WebServicesConfiguration.get_Current()
--- End of inner exception stack trace --- at
Microsoft.Web.Services3.Configuration.WebServicesConfiguration.get_Current()
at
Microsoft.Web.Services3.Configuration.WebServicesConfiguration.get_MessagingConfiguration()
at
Microsoft.Web.Services3.WseProtocol.ModifyInitializedExtensions(PriorityGroup
group, SoapExtension[] extensions) at
System.Web.Services.Protocols.SoapServerProtocol.Initialize() --- End of
inner exception stack trace --- --- End of inner exception stack
trace ---
There doesn't appear to be anything wrong with the section the error refers
to:
<!-- WSE 3.0 config section -->
<microsoft.web.services3>
<diagnostics>
<trace enabled="true" input="InputTrace.webinfo"
output="OutputTrace.webinfo" />
</diagnostics>
<security>
<securityTokenManager>
<add type="MyAuthorizationLib.MyUserNameTokenManager,
MyAuthorizationLib"
namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
localName="UsernameToken" />
</securityTokenManager>
</security>
<policy fileName="wse3policyCache.config" />
</microsoft.web.services3>
And my wse3policyCache.config file on the server contains:
<policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy">
<extensions>
<extension name="usernameOverTransportSecurity"
type="Microsoft.Web.Services3.Design.UsernameOverTransportAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
<extension name="requireActionHeader"
type="Microsoft.Web.Services3.Design.RequireActionHeaderAssertion,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</extensions>
<policy name="ServerPolicy">
<usernameOverTransportSecurity />
<requireActionHeader />
</policy>
</policies>
What's the most common cause of these WSE040 errors?
Does the fact that I've had to roll my own WSE source files for VS 2008 have
anything to do with it - since there's no handy WSE Config Tool that
integrates with the IDE? (yes, I know the tool can be used standalone, but
it doesn't look like it's fully featured for a custom UserNameTokenManager)
--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault