From: Roland Schmitt Date: 2005-01-10T22:39:27+09:00 Subject: Re: Soap - connecting applications --------------060407020905070907080400 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, Maarten Boonen schrieb: > Hi, > > I made an application in Ruby and want to provide an interface for other > (local) applications to use it. I tried to use SOAP for this purpose (a > good choice?) and it works great with a ruby server and ruby client. But > when i create a C# application to access the ruby server, I can connect > and execute the ruby method, but the result returned is an empty string. > (instead of, for instance, the 'hello world' the server sent out). > Does anybody know whether this is because of some incompatibility > between the message sent and expected by the c# client, or because I > made an error in my c# code? (which I shamelessly copied and slightly > adapted from an online tutorial) > Maarten > > > ------------------------------------------------------------------------ > > namespace HelloService > { > using System.Diagnostics; > using System.Xml.Serialization; > using System; > using System.Web.Services; > using System.Web.Services.Protocols; > > [System.Web.Services.WebServiceBindingAttribute( > Name="SuperDuperTest", > Namespace="www.superdupertest.com")] > > public class HelloProxy: System.Web.Services.Protocols.SoapHttpClientProtocol > { > public HelloProxy() > { > this.Url = "http://localhost:9999/"; > } > > [System.Web.Services.Protocols.SoapDocumentMethodAttribute( > "www.superdupertest.com/hello", > RequestNamespace="www.superdupertest.com", > ResponseNamespace="www.superdupertest.com", > Use=System.Web.Services.Description.SoapBindingUse.Literal, > ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] > public string hello(string name) > { > object [] results = this.Invoke("hello",new object[] { name }); > return ((string)(results[0])); > } > > [STAThread] > static void Main() > { > HelloProxy service = new HelloProxy(); > Console.WriteLine("--->" + service.hello("Robert") + "<---"); > } > } > }//End of HelloService Namespace > > > ------------------------------------------------------------------------ you must provide the [System.Web.Services.Protocols.SoapRpcMethod()] Attribute to your methods like in the example attached. Hope in helps. Regards, Roland --------------060407020905070907080400 Content-Type: text/plain; name="PingService.asmx.cs" Content-Transfer-Encoding: 8bit Content-Disposition: inline; filename="PingService.asmx.cs" using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Serialization; using Microsoft.Web.Services2; using Microsoft.Web.Services2.Security; using Microsoft.Web.Services2.Security.Tokens; using Microsoft.Web.Services2.Security.X509; namespace PingService { [WebService(Namespace="http://localhost/PingService/")] public class Hello : System.Web.Services.WebService { public Hello() { //CODEGEN: Dieser Aufruf ist f�r den ASP.NET-Webdienst-Designer erforderlich. InitializeComponent(); } #region Vom Komponenten-Designer generierter Code //Erforderlich f�r den Webdienst-Designer private IContainer components = null; /// /// Erforderliche Methode f�r die Designerunterst�tzung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor ge�ndert werden. /// private void InitializeComponent() { } /// /// Die verwendeten Ressourcen bereinigen. /// protected override void Dispose( bool disposing ) { if(disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } #endregion [WebMethod] [System.Web.Services.Protocols.SoapRpcMethod()] public string SayHello(string name) { SoapContext requestContext = Microsoft.Web.Services2.RequestSoapContext.Current; SoapContext responseContext = Microsoft.Web.Services2.ResponseSoapContext.Current; X509SecurityToken x509Token = getToken(); ISecurityTokenManager stm = SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.X509v3); X509SecurityTokenManager x509tm = stm as X509SecurityTokenManager; x509tm.DefaultSessionKeyAlgorithm = "TripleDES"; if (x509Token == null) { throw new SecurityFault(SecurityFault.FailedAuthenticationMessage, SecurityFault.FailedAuthenticationCode); } else { EncryptedData ed = new EncryptedData(x509Token); responseContext.Security.Elements.Add(ed); } return "Hello, " + name; } private X509SecurityToken getToken() { X509SecurityToken token = null; X509CertificateStore store = null; string keyIdentifier = "nRBfsExrZ3BhmPz3ejKQCmiEYbQ="; // Open the CurrentUser Certificate Store and try OtherPeople first //store = X509CertificateStore.CurrentUserStore(X509CertificateStore.RootStore); store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); store.OpenRead(); X509CertificateCollection coll = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(keyIdentifier)); if (coll.Count > 0) { // Get the first certificate in the collection token = new X509SecurityToken( ((X509Certificate) coll[0]) ); } return token; } } } --------------060407020905070907080400--