none
How to Enable MTOM feature on Asp.Net Webapplication which is client RRS feed

  • Question

  • Hi,
    I am trying to consume a java web service which has MTOM feature enabled.
    I developed a Asp.Net aplication as client which consumes the above java webservice.
    How can we enable MTOM feature on the asp.net Client ?
    Thursday, February 18, 2010 1:55 PM

Answers

  • Hi,

    I have solved the issue .

    I enabled MTOM on the Client side and its working fine.

    I used WSe 3.0 tool and load the config file and set all the settings.

    and chamnged the Refernce.cs file which will be genreated by adding as a web reference.

    I chaned the

    public partial class <ServiceClass> : System.Web.Services.Protocols.SoapHttpClientProtocol” to

     “public partial class <ServiceClass>Wse : Microsoft.Web.Services3.WebServicesClientProtocol.

    Make sure to change the in the constructor also.

    Monday, April 26, 2010 11:54 AM

All replies

  • You need to create a WCF client referencing this Java service and use this client to call the service and fetch the data or execute the service operation. Following links will be useful -
    http://msdn.microsoft.com/en-us/library/ms734691.aspx
    http://msdn.microsoft.com/en-us/library/ms735103.aspx
    When you will add the service reference for this Java service to create a WCF client, it will create a binding with MTOM encoding which you can use to access the service. If everything works fine which it should, you do not have to do anything extra other than creating a WCF client and using it as proxy to access your service.
    Thanks.
    - Piyush
    Friday, February 19, 2010 5:49 AM
    Moderator
  • thank you for your reply.

    how can we know whether the Java web service is MTOM enabled .

    I had only WSDl of the web service.

    Friday, February 19, 2010 9:52 AM
  • SOAP web services advertise the service's capabilities through something called policy assertions which are part of WSDL. Your WSDL must have wsoma:OptimizedMimeSerialization policy assertion if your Java web service is MTOM capable.
    http://www.w3.org/Submission/WS-MTOMPolicy/
    e.g. if I enable MTOM encoding on BasichttpBinding on a WCF service - I see the following in my WSDL -
    -       <wsp:Policy wsu:Id="BasicHttpBinding_IService1_policy">
    -       <wsp:ExactlyOne>
    -       <wsp:All>
                 <wsoma:OptimizedMimeSerialization      xmlns:wsoma=http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization />
         </wsp:All>
         </wsp:ExactlyOne>
         </wsp:Policy>

    - Piyush
    Saturday, February 20, 2010 4:41 AM
    Moderator
  • Hi,
    I am not able to view the property RequireMTOM when created proxy for the Javawebservice.
    Even i configured using WSE 3.0.
    Could any one help me in how can i get the property Require.MTOM visible for the proxy created.
    Monday, February 22, 2010 1:18 PM
  • I am assuming that you want to use WCF on the client side. When you added a service reference to your Java service - which binding did it generate? Have a look at this sample here - http://msdn.microsoft.com/en-us/library/aa395209.aspx. I don't think there is any RequireMTOM setting in WCF. You would want to use messageEncoding=MTOM on your binding configuration.
    - Piyush
    Monday, February 22, 2010 4:36 PM
    Moderator
  • Hi,
    Let me explain the situation.
    I have Java service wsdl file.
    The java webservice is MTOM enabled.
    I am consuming the wsdl file in asp.net application by clicking on "Add Webreference".
    Now in the client application,I created a proxy for the java service.
    Now I wanted to Enable MTOM on the client application which is consuming above Java webservice.
    When i tried to configure Client application with WSE 3.0, then i am not able to get "Require MTom" Property on the Client application for the proxy created.

    The problem, Iam facing is
     how to enable asp.net application consuming java web service?
    How to get the "Require.MTOM" property in the client application ?
    Tuesday, February 23, 2010 10:20 AM
  • Hi Ajay,
    It seems that you are actually creating a WSE 3.0 client to talk to Java service. I had assumed that you are creating a WCF client since this is a WCF specific forum and hence the example here - http://msdn.microsoft.com/en-us/library/aa395209.aspx.
    Do you have any particular reason to use WSE? WSE has been obsoleted and replaced by WCF. I think you shuld consider the use of WCF and the above example link can tell you exactly how to configure this for MTOM.
    Thanks.
    - Piyush
    Tuesday, February 23, 2010 4:12 PM
    Moderator
  • hi,
    thank you for your sugguestion.
    My problem how can i enable MTOM on asp.net web application which is consuming that java web service which is mtom enbaled
    Friday, February 26, 2010 4:57 AM
  • Hi Ajay,
    What you need to do is to add a service reference to the Java web service by clicking Add Service Reference providing the URL of the service in your ASP.Net solution. This will generate a WCF client proxy in your ASP.Net solution which will be anabled for MTOM. Now you just have to use this proxy to call the service. This will just be like any other class instance object and it will be just like calling methods on this.
    Thanks.
    - Piyush
    Friday, February 26, 2010 5:48 AM
    Moderator
  • Hi,
    Thank you for quick reply.
    I tried to create web reference and service reference for the java web service.
    with the proxy created.
    how to enable Mtom on the client application where the proxy is created to consume java web service.

    MtOM  feature on Client application ?how to enable MTOM on client side.
    Friday, February 26, 2010 9:59 AM
  • Maybe I am misunderstanding you but please see my previous responses. Have a look at this sample here - http://msdn.microsoft.com/en-us/library/aa395209.aspx. You would want to use messageEncoding=MTOM in your binding configuration.
    This will ensure that when you use this client proxy to send message across to the Java service, it is encoded in MTOM.
    - Piyush
    Friday, February 26, 2010 4:46 PM
    Moderator
  • I solved the issue of getting the property "RequireMTOM" in my client application.

    I tried to generate the proxy by using WseWsdl3.exe .
    I added the proxy to my solution and wrote the below code. 

    WebServicesClientProtocol

     

    obj = new WebServicesClientProtocol();

    obj.RequireMtom =

    true;

    Now Iam able to get the property "RequireMtom".
    When i run the solution I am getting the following error

    'WebServiceBindingAttribute is required on proxy classes'.

    How can i get rid of this.

    Wednesday, March 3, 2010 1:35 PM
  • Did you ever try generating a WCF client proxy to see if it works for you? Or were you facing problems there? Or do you have to generate a WSE client only? As I said before, WSE has been obsoleted and you should use WCF in your applications.

    - Piyush
    Wednesday, March 3, 2010 4:59 PM
    Moderator
  • Hi,
    How to generate WCf client proxy that commmunicates with java web service.
    give me information.
    please let me know how to communicate with java web service
    Thursday, March 4, 2010 4:05 AM
  • Do you have a WSDL to the Java service? You can use this to generate a WCF client proxy by either using svcutil tool or by using Add Service reference in Visual Studio. This will generate a client which can talk to your Java web service. Please see my responses from before. Take a look at this sample here http://msdn.microsoft.com/en-us/library/aa395209.aspx to get an idea about how the client side config will look like which will allow you to enable communicating with this Java web service with MTOM encoding. Please try this and let us know if you still face any problems.
    - Piyush
    Thursday, March 4, 2010 5:38 AM
    Moderator
  • Hi,
    I tried to access the service by adding it as Service reference.
    and i configured the web.config file as i mentioned the MessageEncoding to "MTOM" and now I am getting Error message as "Error creating a reader for the MTOM message".
    I have copied the config file of the client consuming the java web service.

    <system.serviceModel>

      <bindings >

       <basicHttpBinding >

        <binding name="PMServiceSoapBinding" closeTimeout="00:01:00"

         openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

         allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

         maxBufferSize="67108864" maxBufferPoolSize="67108864" maxReceivedMessageSize="67108864"

         messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" >

         <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

          maxBytesPerRead="4096" maxNameTableCharCount="16384" />

         <security mode="None" >

          <transport clientCredentialType="None" proxyCredentialType="None"

           realm=""  />

          <message clientCredentialType="UserName" algorithmSuite="Default"  />

         </security>

        </binding>

       </basicHttpBinding>

      </bindings>

      <client >

       <endpoint address="URL"

        binding="basicHttpBinding" bindingConfiguration="PMServiceSoapBinding" 

        contract="ServiceReference1.PMService" name="ProjectManagerServicePort" />

      </client>

     </system.serviceModel>

     <applicationSettings>

      <sampleWebApplication.Properties.Settings>

       <setting name="sampleWebApplication_com_PMService" 

        serializeAs="String">

        <value>URL</value>

       </setting>

      </sampleWebApplication.Properties.Settings>

     </applicationSettings>

    </configuration>

    Tuesday, March 9, 2010 9:29 AM
  • Do you see the following policy assertion in the WSDL of your service -
    <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" />
    Did you have to add the messageEncoding="MTOM" by yourself in the client proxy? Normally if the service supports MTOM (which is indicated by the presence of the policy assertion in WSDL), when we generate a client proxy - it will contain messageEncoding=MTOM automatically and we do not have to manually edit the config file.
    When do you get the error message - when you send or receive a message? I am assuming that this error is on the client side? Can you paste the exception stack? What platform/technology is the service side? Does you service supports both sending and receing MTOM messages. I know of a limitation in WCF where once MTOM enabled, we mandate that both request and responses must be MTOM and there are some other Java stacks which accept MTOM but send response as Text encoded. You can find if this is your case by turning on Fiddler and intercepting the traffix b/w client and service.
    Thanks.
    - Piyush
    Tuesday, March 9, 2010 7:50 PM
    Moderator
  • Hi,
    I have copied the System.Trace information.PLease go through it and let me know.
    In the client config file,I got the TextEncoding as TEXT which i modified to MTOM because I am trying to consume a JAVA Webservice which is MTOM enabled.
    Please help me in fixing this issue.

    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at sampleWebApplication.ServiceReference1.PMService.createSimpleMTOMProject(createSimpleMTOMProject1 request) at sampleWebApplication.ServiceReference1.PMServiceClient.sampleWebApplication.ServiceReference1.PMService.createSimpleMTOMProject(createSimpleMTOMProject1 request) at sampleWebApplication.ServiceReference1.PMServiceClient.createSimpleMTOMProject(createSimpleMTOMProject createSimpleMTOMProject1) at sampleWebApplication._Default.BtnUpload_Click(Object sender, EventArgs e) <form id="form1" action="Default.aspx" enctype="application/x-www-form-urlencoded" method="post"></form>
    Thursday, March 11, 2010 3:18 PM
  • Ajay,
    1. Do you know for sure that the service on the other end supports MTOM?
    2. Can you confirm if you see the following policy assertion in the WSDL of your service -
    <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" /> ?
    3. Alternatively, can you just see if keeping the messageEncoding value unchanged (ie = "Text") worsks?
    4. If not, can you upload the full error traces (verbose) here - skydrive.live.com? I am not able to figure out anything from the portion you pasted above.

    - Piyush
    Thursday, March 11, 2010 5:39 PM
    Moderator
  • Hi,
    1)Java Service  which i am consuming is MTOM enabled.
    2)I did not find the statement  which you mentioned  in the wsdl file
    3)Even i tried with out making chnages in the Text Encoding to"TEXT" but it generates a error.
    4) I have uploaded the  full error trace information


    [XmlException: Unexpected type 'text/xml; charset=UTF-8' found in root MIME part. Message header specifies 'text/xml'.]
       System.Xml.XmlMtomReader.ReadRootContentTypeHeader(ContentTypeHeader header, Encoding[] expectedEncodings, String expectedType) +366251
       System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize) +286
       System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose) +47
       System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose) +61
       System.Xml.XmlDictionaryReader.CreateMtomReader(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose) +57
       System.ServiceModel.Channels.MtomBufferedMessageData.TakeXmlReader() +223

    [CommunicationException: Error creating a reader for the MTOM message]
       System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +7596735
       System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +275
       sampleWebApplication.ServiceReference1.PMService.createSimpleMTOMProject(createSimpleMTOMProject1 request) +0
    Friday, March 12, 2010 9:07 AM
  • I suspect that the Java service is accepting an MTOM request but retuning an XML response something which as I stated above, is not supported by WCF. Can you paste the response from the service using any http capture tools like fiddler to confirm this?
    Thanks.
    - Piyush
    Saturday, March 13, 2010 7:50 PM
    Moderator
  • Hi,

     The issue is request & response content types of the service which i am consuming are different. Response content type is “application/xop+xml” but required type is “”text\xml”. So,i created custom soap extension to convert this “application/xop+xml” type to SOAP type

    The sample implementation is given in a blog post. The link is shared here.

    http://coding.baneworld.nl/2009/02/client-found-response-content-type-of-multipartrelated-but-expected-textxml/

    When i tried to create a custom soap extension class I am  facing the following error as:

    'encoding' is an unexpected token. The expected token is '?>'

     Stack Trace of the Error:

    [XmlException: 'encoding' is an unexpected token. The expected token is '?>'. Line 1, position 20.]
       System.Xml.XmlTextReaderImpl.Throw(Exception e) +76
       System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) +88
       System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2) +167
       System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) +3980579
       System.Xml.XmlTextReaderImpl.Read() +239
       System.Xml.XmlTextReader.Read() +15
       System.Xml.XmlReader.MoveToContent() +64
       System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +502
       System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
     
    [InvalidOperationException: Response is not well-formed XML.]
       System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +282
       LingoTest.com.lingo24.xtm_test.PMService.createSimpleMTOMProject(createSimpleMTOMProject createSimpleMTOMProject1) in C:\Documents and Settings\ajay.chigurupati\My Documents\Visual Studio 2008\Projects\ASP.NET\LingoTest\Web References\com.lingo24.xtm-test\Reference.cs:170
       LingoTest._Default.Button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\ajay.chigurupati\My Documents\Visual Studio 2008\Projects\ASP.NET\LingoTest\Default.aspx.cs:78
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Saturday, March 20, 2010 5:01 AM
  • Hi Ajay,

    Sending and receiving different content-types is uncommon and not supported in WCF. I am assuming you have created an ASP.Net web services client now (since you are using the SOAP extensions which are not used with WCF technology).

    I don't know enough of SOAP extensions (you would be better off posting this question about help with this error message in ASMX forum - http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads.


    - Piyush
    Saturday, March 20, 2010 6:52 AM
    Moderator
  • Thank you for your support.

    Saturday, March 20, 2010 1:35 PM
  • Hi,

    I have solved the issue .

    I enabled MTOM on the Client side and its working fine.

    I used WSe 3.0 tool and load the config file and set all the settings.

    and chamnged the Refernce.cs file which will be genreated by adding as a web reference.

    I chaned the

    public partial class <ServiceClass> : System.Web.Services.Protocols.SoapHttpClientProtocol” to

     “public partial class <ServiceClass>Wse : Microsoft.Web.Services3.WebServicesClientProtocol.

    Make sure to change the in the constructor also.

    Monday, April 26, 2010 11:54 AM