I learning WSE.
My Web service not authenticate UsernameToken with password SendHashed.
Error text:
System.Web.Services.Protocols.SoapHeaderException: Server unavailable, please try later ---> System.Configuration.ConfigurationException: WSE032: There was an error loading the microsoft.web.services2 configuration section. ---> System.Configuration.ConfigurationErrorsException: WSE040: Type myWSE.CustomUsernameTokenManager could not be loaded. Please check the configuration file. 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.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.ConfigurationSettings.GetConfig(String sectionName) at Microsoft.Web.Services2.Configuration.WebServicesConfiguration.Initialize() --- End of inner exception stack trace --- at Microsoft.Web.Services2.Configuration.WebServicesConfiguration.Initialize() at Microsoft.Web.Services2.WebServicesExtension.BeforeDeserializeServer(SoapServerMessage message) --- End of inner exception stack trace ---
My service:
namespace myWSE
{
[WebService(Namespace = " http://www.hide-link.com/ ")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ServiceWse : System.Web.Services.WebService
{
public ServiceWse()
{ }
[ WebMethod]
pblic string HelloWorld()
{
SoapContext requestContext = RequestSoapContext.Current;
// Verify that a SOAP request was received.
if (requestContext == null)
{
throw new ApplicationException("Either a non-SOAP " +
"request was received or WSE is not properly " +
"installed for the Web application hosting the " +
"Web service.");
}
return " Yo";
}
[System.Security.Permissions. SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags = System.Security.Permissions. SecurityPermissionFlag.UnmanagedCode)]
public class CustomUsernameTokenManager : UsernameTokenManager
{
protected override string AuthenticateToken(UsernameToken userName)
{
// Ensure that the SOAP message sender passed a UsernameToken.
if (userName == null)
throw new ArgumentNullException();
return "localpass";
}
}
}
web.config file:
< configuration>
< configSections>
< section name="microsoft.web.services2" type="Microsoft.Web.Services2.Configuration.WebServicesConfiguration, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</ configSections>
< appSettings />
< connectionStrings />
< system.web>
< compilation debug="true">
< assemblies>
< add assembly="Microsoft.Web.Services2, Version=2.0.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</ assemblies>
</ compilation>
< webServices>
< soapExtensionTypes>
< add type="Microsoft.Web.Services2.WebServicesExtension, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="1" group="0" />
</ soapExtensionTypes>
</ webServices>
</ system.web>
< microsoft.web.services2>
< security>
< securityTokenManager type="myWSE.CustomUsernameTokenManager" xmlns:wsse=" http://www.hide-link.com/ " qname="wsse:UsernameToken"/>
</ security>
</ microsoft.web.services2>
</ configuration>
My client:
private void button1_Click(object sender, EventArgs e)
{
Client.localhost. ServiceWse proxy = new Client.localhost.ServiceWse();
proxy.RequestSoapContext.Security.Timestamp.TtlInSeconds = Convert.ToInt32(textBox1.Text);
UsernameToken tok = new UsernameToken(nameTb.Text, passTb.Text, (PasswordOption)comboBox1.SelectedItem);
proxy.RequestSoapContext.Security.Tokens.Add(tok);
if (checkBox1.Checked == true)
{
Signature sig = new Signature(tok);
proxy.RequestSoapContext.Security.Elements.Add(sig);
}
try
{
label1.Text = proxy.HelloWorld();
}
catch
{
textBox2.Text = "Error";
}
}
Where my mistakes
.NET Development20
|