SOAP WebService with SOAP Header Attributes failing

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SOAP WebService with SOAP Header Attributes failing

Matronix
This post was updated on .
When trying to create my service object my code will throw an exception stating:

System.InvalidOperationException has been thrown
Member LicenseInfoValueField not found in class TestProject.localhost.Service

When I go to the reference.cs file this is the top:

namespace TestProject.localhost {
    [System.Web.Services.WebServiceBinding(Name="ServiceSoap",Namespace="http://XYZ/TestProduct/")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class Service : System.Web.Services.Protocols.SoapHttpClientProtocol {

         private LicenseInfo LicenseInfoValueField;
         private ErrorInfo ErrorInfoValueField;


LicenseInfo and ErrorInfo are the attributes

Here is a webservice method:

        [WebMethod(EnableSession = true)]
        [SoapHeader("LicenseInfo", Direction = SoapHeaderDirection.In)]
        [SoapHeader("ErrorInfo", Direction = SoapHeaderDirection.Out)]
        public Guid CreateContainer(string name, string description)


Any clue why I wouldn't be able to create the Service object and talk to my Web Service?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

Jackson Harper
Try adding the Preserve attribute to all the classes in your generated file.

[Preserve (AllMembers = true)]
class SomeClass



Sent from my iPhone

On Jan 4, 2012, at 10:04 AM, Matronix <[hidden email]> wrote:

> When trying to create my service object my code will throw an exception
> stating:
>
> System.InvalidOperationException has been thrown
> Member LicenseInfoValueField not found in class
> TestProject.localhost.Service
>
> When I go to the reference.cs file this is the top:
>
> namespace TestProject.localhost {
>
> [System.Web.Services.WebServiceBinding(Name="ServiceSoap",Namespace="http://C2S/ImageDirector/")]
>    [System.Diagnostics.DebuggerStepThroughAttribute()]
>    [System.ComponentModel.DesignerCategoryAttribute("code")]
>    public partial class Service :
> System.Web.Services.Protocols.SoapHttpClientProtocol {
>
>         private LicenseInfo LicenseInfoValueField;
>         private ErrorInfo ErrorInfoValueField;
>
>
> LicenseInfo and ErrorInfo are the attributes
>
> Here is a webservice method:
>
>        [WebMethod(EnableSession = true)]
>        [SoapHeader("LicenseInfo", Direction = SoapHeaderDirection.In)]
>        [SoapHeader("ErrorInfo", Direction = SoapHeaderDirection.Out)]
>        public Guid CreateContainer(string name, string description)
>
>
> Any clue why I wouldn't be able to create the Service object and talk to my
> Web Service?
>
> --
> View this message in context: http://monotouch.2284126.n4.nabble.com/SOAP-WebService-with-SOAP-Header-Attributes-failing-tp4261555p4261555.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

Matronix
I just did a quick search on  [Preserve (AllMembers = true)].  Am I correct in thinking that it is a MonoTouch tag only?

The webservice that I am talking to is written with C# and Visual Studio. 


On Wed, Jan 4, 2012 at 10:24 AM, Jackson Harper <[hidden email]> wrote:
Try adding the Preserve attribute to all the classes in your generated file.

[Preserve (AllMembers = true)]
class SomeClass



Sent from my iPhone

On Jan 4, 2012, at 10:04 AM, Matronix <[hidden email]> wrote:

> When trying to create my service object my code will throw an exception
> stating:
>
> System.InvalidOperationException has been thrown
> Member LicenseInfoValueField not found in class
> TestProject.localhost.Service
>
> When I go to the reference.cs file this is the top:
>
> namespace TestProject.localhost {
>
> [System.Web.Services.WebServiceBinding(Name="ServiceSoap",Namespace="http://C2S/ImageDirector/")]
>    [System.Diagnostics.DebuggerStepThroughAttribute()]
>    [System.ComponentModel.DesignerCategoryAttribute("code")]
>    public partial class Service :
> System.Web.Services.Protocols.SoapHttpClientProtocol {
>
>         private LicenseInfo LicenseInfoValueField;
>         private ErrorInfo ErrorInfoValueField;
>
>
> LicenseInfo and ErrorInfo are the attributes
>
> Here is a webservice method:
>
>        [WebMethod(EnableSession = true)]
>        [SoapHeader("LicenseInfo", Direction = SoapHeaderDirection.In)]
>        [SoapHeader("ErrorInfo", Direction = SoapHeaderDirection.Out)]
>        public Guid CreateContainer(string name, string description)
>
>
> Any clue why I wouldn't be able to create the Service object and talk to my
> Web Service?
>
> --
> View this message in context: http://monotouch.2284126.n4.nabble.com/SOAP-WebService-with-SOAP-Header-Attributes-failing-tp4261555p4261555.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

Matronix
In reply to this post by Matronix
The assumption is that there is an issue with SoapHeaders and MonoTouch.  I submitted a bug report.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

Highflyer
In reply to this post by Matronix
Hi, I met this bug too, has it been solved?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

spcware
I was able to solve it.  In order to get a valid SOAP client using Xamarin/Monotouch running on iOS, you must use the Silverlight soap proxy generator:  slsvcutil.exe.  this is because iOS does not allow dynamic code execution and the standard soap proxy generator:  svcutil.exe  creates a client that depends on dynamic code execution.  The Silverlight generator produces a simpler client without dynamic code execution.  However, it is too simple in that it does NOT support soap headers.

My solution to this problem is to still use the Silverlight soap proxy generator, but then implement 2 classes to manually add in the soap headers before the soap requests go out during runtime.  Here are the two classes I implemented.  You will see that the second class contains the BeforeSendRequest method which I override to manually add in my soap headers.  Of course, your soap headers will be different than mine.  Then to use these two classes, you add an endpoint behavior to your client when you construct it:  client.Endpoint.Behaviors.Add (new EditorialSoapHeaderBehavior (appName,sessionId));

                private class EditorialSoapHeaderBehavior : IEndpointBehavior
                {
                        private string _appName = null;
                        private string _sessionId = null;

                        public EditorialSoapHeaderBehavior(string appName,string sessionId)
                        {
                                _appName = appName;
                                _sessionId = sessionId;
                        }

                        public void AddBindingParameters (ServiceEndpoint endpoint, BindingParameterCollection parameters)
                        {
                        }
                        public void ApplyDispatchBehavior (ServiceEndpoint endpoint, EndpointDispatcher dispatcher)
                        {
                        }
                        public void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime runtime)
                        {
                                runtime.MessageInspectors.Add (new EditorialSoapHeaderInspector (_appName,_sessionId));
                        }
                        public void Validate (ServiceEndpoint endpoint)
                        {
                        }
                }

                private class EditorialSoapHeaderInspector : IClientMessageInspector
                {
                        private string _appName = null;
                        private string _sessionId = null;

                        public EditorialSoapHeaderInspector(string appName,string sessionId)
                        {
                                _appName = appName;
                                _sessionId = sessionId;
                        }

                        public void AfterReceiveReply (ref Message message, object correlationState)
                        {
                        }
                        public object BeforeSendRequest (ref Message message, IClientChannel channel)
                        {
                                MessageHeader mh = MessageHeader.CreateHeader ("ApplicationName", "IHS.Core.Security.WCF", _appName);
                                message.Headers.Add (mh);
                                mh = MessageHeader.CreateHeader ("SessionId", "IHS.Core.Security.WCF", _sessionId);
                                message.Headers.Add (mh);
                                return(null);
                        }
                }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

Gusman
In my case i'm using wsdl.exe in windows to generate the proxy and works like a charm, just copy the generated .cs and everything works perfect.


2014-03-27 7:29 GMT+01:00 spcware <[hidden email]>:
I was able to solve it.  In order to get a valid SOAP client using
Xamarin/Monotouch running on iOS, you must use the Silverlight soap proxy
generator:  slsvcutil.exe.  this is because iOS does not allow dynamic code
execution and the standard soap proxy generator:  svcutil.exe  creates a
client that depends on dynamic code execution.  The Silverlight generator
produces a simpler client without dynamic code execution.  However, it is
too simple in that it does NOT support soap headers.

My solution to this problem is to still use the Silverlight soap proxy
generator, but then implement 2 classes to manually add in the soap headers
before the soap requests go out during runtime.  Here are the two classes I
implemented.  You will see that the second class contains the
BeforeSendRequest method which I override to manually add in my soap
headers.  Of course, your soap headers will be different than mine.  Then to
use these two classes, you add an endpoint behavior to your client when you
construct it:  client.Endpoint.Behaviors.Add (new
EditorialSoapHeaderBehavior (appName,sessionId));

                private class EditorialSoapHeaderBehavior : IEndpointBehavior
                {
                        private string _appName = null;
                        private string _sessionId = null;

                        public EditorialSoapHeaderBehavior(string appName,string sessionId)
                        {
                                _appName = appName;
                                _sessionId = sessionId;
                        }

                        public void AddBindingParameters (ServiceEndpoint endpoint,
BindingParameterCollection parameters)
                        {
                        }
                        public void ApplyDispatchBehavior (ServiceEndpoint endpoint,
EndpointDispatcher dispatcher)
                        {
                        }
                        public void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime
runtime)
                        {
                                runtime.MessageInspectors.Add (new EditorialSoapHeaderInspector
(_appName,_sessionId));
                        }
                        public void Validate (ServiceEndpoint endpoint)
                        {
                        }
                }

                private class EditorialSoapHeaderInspector : IClientMessageInspector
                {
                        private string _appName = null;
                        private string _sessionId = null;

                        public EditorialSoapHeaderInspector(string appName,string sessionId)
                        {
                                _appName = appName;
                                _sessionId = sessionId;
                        }

                        public void AfterReceiveReply (ref Message message, object
correlationState)
                        {
                        }
                        public object BeforeSendRequest (ref Message message, IClientChannel
channel)
                        {
                                MessageHeader mh = MessageHeader.CreateHeader ("ApplicationName",
"IHS.Core.Security.WCF", _appName);
                                message.Headers.Add (mh);
                                mh = MessageHeader.CreateHeader ("SessionId", "IHS.Core.Security.WCF",
_sessionId);
                                message.Headers.Add (mh);
                                return(null);
                        }
                }




--
View this message in context: http://monotouch.2284126.n4.nabble.com/SOAP-WebService-with-SOAP-Header-Attributes-failing-tp4261555p4658561.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SOAP WebService with SOAP Header Attributes failing

Highflyer
Thanks for your reply, good job!
I used wsdl.exe to generate the consumer code, and I add namespace lines and another constructor:

        public FooService(string url)
        {
                this.Url = url;
        }

It works! Thanks!
Loading...