yangzhenliang 2005年03月25日
Server unavailable, please try later??
每次运行WSE的证书中,客户端都返回这个东西,我知道是我的WEBSERIVCE中出错,但我想把真正出错的EXCEPTION返回来,怎么做呀,我用的是Server :windows 2003_IIS6 client:windows 2000
还有就是2000跟 2000是没问题,用windo2003本身自己写也没有问题,server的代码是
[WebMethod]
// [LogWebservice.TraceExtension(Filename="e:\\Inetpub\\log.txt")]
public string HelloWorld(string yy)
{
return "Hello World"+yy;
}
client的代码是这样的
public void run()
{
try
{
// Get an X.509 certificate for signing the SOAP message.
// wfg.Service1Wse svc=new wfg.Service1Wse();
roothost.Service1Wse svc = new roothost.Service1Wse();
//localhost.TestWebService svc=new TestCon509.localhost.TestWebService();
SoapContext requestContext = svc.RequestSoapContext;

X509SecurityToken signatureToken = GetSecurityToken(true);
if (signatureToken == null)
{
return;
}

// Add the X.509 certificate to the header.
requestContext.Security.Tokens.Add(signatureToken);

// Specify that the SOAP message is signed using this X.509
// certifcate.
MessageSignature sig = new MessageSignature(signatureToken);
requestContext.Security.Elements.Add(sig);

// Get an X.509 certificate for encrypting the SOAP message.

X509SecurityToken encryptionToken = GetSecurityToken(false);
if (encryptionToken == null)
{
return;
}
// Add the X.509 certificate to the WS-Security header.
requestContext.Security.Tokens.Add(encryptionToken);
//requestContext.Security.Elements.Add( new MessageSignature( encryptionToken ) );

// Specify that the SOAP message is encrypted using
// this X.509 certificate.

EncryptedData enc = new EncryptedData(encryptionToken);
requestContext.Security.Elements.Add(enc);


// Set the TTL to 1 minute.
requestContext.Security.Timestamp.TtlInSeconds = 600;

// Make the SOAP request to the Web service.
//svc.HelloWorld("tt");
System.Console.WriteLine("ff:"+svc.HelloWorld("yzl tt"));
}
catch (Exception ex)
{
System.Console.WriteLine(ex.ToString());
}


System.Console.WriteLine("23423");
}
public X509SecurityToken GetSecurityToken(bool IsTokenForSigning)
{
X509CertificateStore store;
X509SecurityToken securityToken = null;
// Open the certificate store for the currently
// logged-in user.
store = X509CertificateStore.CurrentUserStore(
X509CertificateStore.MyStore);
bool open = store.OpenRead();

try
{
// Retrieve the certificate by using its SHA-1 hash.
byte[] certHash = {0x98, 0xec, 0x08, 0x4b, 0xa5, 0x7a,
0x6c, 0x2f, 0x39, 0x26, 0xb3, 0x0a,
0x58, 0xbf, 0x65, 0x25, 0x61, 0xc5,
0x64, 0x59};
//X509CertificateCollection certs = store.FindCertificateByKeyIdentifier( Convert.FromBase64String( "laHUPmL3NQtIOTaekDUhOkfeWC8=" ) );
X509CertificateCollection certs = store.FindCertificateByKeyIdentifier( Convert.FromBase64String( "+Stalzi5EvrL3+O5bReFA4nMJMo=" ) );
//X509CertificateCollection certs =store.FindCertificateByHash(certHash);

System.Console.WriteLine("count:"+certs.Count);
Microsoft.Web.Services2.Security.X509.X509Certificate cert =
((Microsoft.Web.Services2.Security.X509.X509Certificate) certs[0]);

if (cert == null)
{
System.Console.WriteLine("Could not find the X.509 certificate.");
securityToken = null;
}
else if (cert == null || !cert.SupportsDataEncryption)

{

throw new ApplicationException("Service is not able to encrypt the response");



return null;

}


// If the requested token is for signing, verify that
// the certificate supports digital signatures and has
// a private key available.
else if ((IsTokenForSigning) &&
(!cert.SupportsDigitalSignature ||
(cert.Key == null)))
{
System.Console.WriteLine("The certificate must support " +
"digital signatures and have a private key available.");
securityToken = null;
}
// If the requested token is for encryption, verify
// that the certificate supports data encryption.
else if ((!IsTokenForSigning) &&!(cert.SupportsDataEncryption))
{
System.Console.WriteLine("The certificate must support data encryption.");
securityToken = null;
}
else
{
securityToken = new X509SecurityToken(cert);
}
}
finally
{
if (store != null) { store.Close(); }
}
return securityToken;
}
}
...全文
124 点赞 收藏 5
写回复
5 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Web Services
创建于2007-09-28

1.1w+

社区成员

1.6w+

社区内容

.NET技术 Web Services
社区公告
暂无公告