locked
is it possible to change the layout of a webservice (asmx file)? RRS feed

  • Question

  • User-1008348326 posted

    Hi,

    I created some webservices (asmx files). When consuming them directly, i see always the same layout. I
    can see the html-code of the .asmx file (view / source) but is it possible to change the source or it's hardcoded and so not accessible?
    Thanks

    Wednesday, December 27, 2006 4:33 AM

All replies

  • User-1614457691 posted

    Hi,

    I created some webservices (asmx files). When consuming them directly, i see always the same layout. I
    can see the html-code of the .asmx file (view / source) but is it possible to change the source or it's hardcoded and so not accessible?
    Thanks

    tartuffe2 --

    I am sorry; but the question is not clear to me.

    That is because if one creates a web service with VS.NET 2005, then the "Service1.asmx" file contains only one line, something like this...

    <%@ WebService Language="C#" CodeBehind="~/App_Code/Service1.cs" Class="Service1" %>

    ...and all of the code is in another file, such as "Service1.cs".

    Therefore, I am wondering-- what exactly would one mean by wanting to "change the layout of the asmx file"?

    There is only one line-- so, what would one want to change?

    A web service, by nature, has no user-interface or "layout".

    (Perhaps I have misunderstood the question?)

    Note that one could change the single line in the Service1.asmx file by adding attributes; but, AFAIK, that is about all that would ever need to change.

    Note that neither the Service1.cs file nor the Service1.asmx file are "hardcoded". Either can be changed by the developer at any time.

    If it is the case that one has not separated the service into 2 files, asmx and cs, then one should separate them ASAP. This will facilitate maintenance, separation of responsibility, organization of the code base, and so on. It is generally a very good idea to separate such code into 2 files.

    If possilbe, please elaborate on the quesiton a bit.

    HTH.

    Thank you.

    -- Mark Kamoski

    Wednesday, December 27, 2006 9:16 AM
  • User-1008348326 posted

    Hi, Mark

    thanks for eplying... i'll try to be more clear.

    When i request this asmx file (consuming directly the webserbice) here below in the browser (with http), i get a standard layout (upper blue bar with "WebService" in white, then a black fat point and the name of the function + additional text like "The following operations are supported. For a formal definition, please review the Service Description. " etc ...

    My question is: can i change e.g. the blue bar into green and the white text into yellow etc ...? When i click on View  / Source, i see a lot of css and html-code (<div , <li, <tabel ... etc). Where does that come from? Can i change that? Thanks again.

      Here is the code (i put for simplify all in one asmx file, no code-behind file):

    <%@ WebService Language="VB" Class="WebService" %>

    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Xml.Serialization

    <WebService(Description:="Welcome to my first webservice", Namespace:="http://myserver/test/")> _
        Public Class WebService
        Inherits System.Web.Services.WebService
        <WebMethod(Description:="Adds 10 to a number.")> _
        Public Function AddTen(ByVal theNumber As Integer) As Integer
            Return theNumber + 10
      End Function

     End Class

    Wednesday, December 27, 2006 11:55 AM
  • User-1614457691 posted

    Hi, Mark

    thanks for eplying... i'll try to be more clear.

    When i request this asmx file (consuming directly the webserbice) here below in the browser (with http), i get a standard layout (upper blue bar with "WebService" in white, then a black fat point and the name of the function + additional text like "The following operations are supported. For a formal definition, please review the Service Description. " etc ...

    ...

    tartuffe2 --

    Ah ha. Now I know what you are talking about in your post.

    That page that you are seeing is generated automatically.

    It can be turned off (hidden) from public viewing.

    As far as formatting that page, I do not know how to do it.

    If you really need control over such a page, then I would suggest building a web site application that exposes the functionality that you want. Then you can format it according to your own style. I would not rely on the auto-generated testing page because that may change when VS.NET changes and it is ultimately out of your control, AFAIK.

    I am sorry that I cannot help further.

    Thank you.

    -- Mark Kamoski

    Wednesday, December 27, 2006 12:08 PM
  • User-1008348326 posted

    Thanks. 

    One last thing: how can this page be hidden from public viewing?

     

     

    Wednesday, December 27, 2006 1:41 PM
  • User-1614457691 posted

    Thanks. 

    One last thing: how can this page be hidden from public viewing?

    tartuffe2 --

    I do not know how to specify that this should happen and have not looked at it closely.

    However, in my current application, I deploy in Release mode and when I do that, the ASMX testing page is not shown unless the browser is running on the deployment server.

    Of note, perhaps, is that Web.config has the following in it...

    <compilation defaultLanguage="c#" debug="false" />

    <customErrors mode="RemoteOnly"/>

    ...but I am not sure if either of those really makes a difference to the "show/dont-show the testing page" situation. They might affect it; but, they might not. 

    Anyway, since I did not change anything from the the default configuation of a new web service project, it seems to me that the default behavior is to not show the testing page unless one is running on the server that is running the service.

    That's about all that I know about it.

    HTH.

    Thank you.

    -- Mark Kamoski

    Wednesday, December 27, 2006 2:18 PM
  • User-1008348326 posted
    Thanks
    Thursday, December 28, 2006 4:32 AM
  • User112569707 posted

    You can change the contents of the automatically generated page in machine.config on the web server.

    Read here for more info : http://msdn.microsoft.com/en-us/library/b2c0ew36(VS.71).aspx

    Thursday, December 28, 2006 5:15 AM
  • User-1557435834 posted

    It is not possible to change the content of the asmx page but can control some of the parameters of the service:  Such as which functions to call or whether or not display the WSDL and the asmx page itself.

    More information on : http://msdn.microsoft.com/en-us/library/b2c0ew36(VS.71).aspx

    Wednesday, November 11, 2015 4:05 PM