这是我的代码:
[WebMethod]
public string HelloWorld()
{
return "HelloWorld";
}
//-----------------------------------------------------------
public static String ObtenerTimeStamp(DateTime fechaInicio, DateTime fechaFinal)
{
string timeStamp = "<u:Timestamp xmlns:u=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" u:Id=\"_0\"><u:Created>" + fechaInicio.ToString("yyyy-MM-dd'T'HH:mm:ss") + "</u:Created><u:Expires>" + fechaFinal.ToString("yyyy-MM-dd'T'HH:mm:ss") + "</u:Expires></u:Timestamp>";
return timeStamp;
}
private static string ObtenerSignedInfo(string digestValue)
{
return "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></CanonicalizationMethod><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"></SignatureMethod><Reference URI=\"#_0\"><Transforms><Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></Transform></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></DigestMethod><DigestValue>" + digestValue + "</DigestValue></Reference></SignedInfo>";
}
private static string CreaDigestValue(byte[] bytesTimeStamp)
{
try
{
byte[] digestValueBytes = Org.BouncyCastle.Security.DigestUtilities.CalculateDigest("sha1", bytesTimeStamp);
var digestValue = Convert.ToBase64String(digestValueBytes);
return digestValue;
}
catch { return null; }
}
private static string ObtenerSoap(string fechaInicio, string fechaFinal, string certificado, string signatureValue, string digestValue)
{
String guid = "uuid-b246ed31-bfec-804a-5212-095ac6d97d3c-1";
String envelope = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:u=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"><s:Header><o:Security s:mustUnderstand=\"1\" xmlns:o=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><u:Timestamp u:Id=\"_0\"><u:Created>" + fechaInicio + "</u:Created><u:Expires>" + fechaFinal + "</u:Expires></u:Timestamp><o:BinarySecurityToken u:Id=\"" + guid + "\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + certificado + "</o:BinarySecurityToken><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#_0\"><Transforms><Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>" + digestValue + "</DigestValue></Reference></SignedInfo><SignatureValue>" + signatureValue + "</SignatureValue><KeyInfo><o:SecurityTokenReference><o:Reference ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" URI=\"" + "#uuid-b246ed31-bfec-804a-5212-095ac6d97d3c-1" + "\"/></o:SecurityTokenReference></KeyInfo></Signature></o:Security></s:Header><s:Body><Autentica xmlns=\"http://DescargaMasivaTerceros.gob.mx\"/></s:Body></s:Envelope>";
return envelope;
}
//----------------------------------------------------------
[WebMethod]
public string ConversionXML(DateTime FechaI, DateTime FechaF, X509Certificate2 cert)
{
if (FechaI == null && FechaF == null && cert == null)
{
return null;
}
else
{
string timeStamp = ObtenerTimeStamp(FechaI, FechaF);
var digest = CreaDigestValue(System.Text.Encoding.UTF8.GetBytes(timeStamp));
var signedInfo = ObtenerSignedInfo(digest);
var signatureValue = Firma.Firmar(System.Text.Encoding.UTF8.GetBytes(signedInfo), cert);
var certString = Convert.ToBase64String(cert.GetRawCertData());
string soap = ObtenerSoap(FechaI.ToString("yyyy-MM-dd'T'HH:mm:ss"), FechaI.AddMinutes(5).ToString("yyyy-MM-dd'T'HH:mm:ss"), certString, signatureValue, digest);
return soap;
}
}
当2个webMethod发布并尝试调用其中一个时,错误显示,似乎我需要调用webservice中的所有方法,如果我从第二个中删除“WebMethod”,它会正确调用HelloWorld方法,你知道怎么做发布 2 个或多个时,我只调用其中一种方法?