views:

45

answers:

1

We have a C# Web Service that declares itself using attributes. The code-behind file looks like:

[WebService(Namespace = "http://the.web.service.url/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public sealed class TheWebservice : WebService
{
    [WebMethod]
    public SomeObject TheFunction()
    ...

The web services has worked for a long time now. Recently, one request resulted in an error:

The maximum string content length quota (8192) has been exceeded while reading XML data.

After searching around, I found that there is a setting maxStringContentLength that can increase the meaximum size. The post says you can configure this setting in Web.config in the BasicHttpBinding section. You can then specify that BasicHttpBinding in an endpoint section. But since we declare the webservice using the WebService attribute in the code-behind file, we do not have an endpoint section.

Is there a way to specify an endpoint using a declarative attribute? Alternatively, is it possible to switch from attribute to web.config mode without breaking existing clients? Am I confusing WCF and its predecessor here?

A: 

WebServiceAttribute is used for ASMX web services. BasicHttpBinding is used in WCF web services. These technologies are not related so setting BasicHttpBinding in configuration on your server will not affect behavior of your ASMX web service. Where does the error occured? On the server or on the client? Is your client WCF or ASMX based?

Edit: Because my previous answer is not clear I'm adding this clarification. When you are using ASMX web service (based on WebServiceAttribute) you cannot use WCF configuration (system.serviceModel) to change its behavior. Those are two different APIs. BUT you can use WCF based client to call/consume ASMX web service and in special conditions you can use ASMX based client to call WCF service.

Ladislav Mrnka
That clears things up: I thought WCF was an evolution of ASMX that still used ASMX files. We're definitely using ASMX. So I guess my question is, is there a way to set maxStringContentLength in an ASMX file?
Andomar
Right, now that I know the difference it all makes sense. We use a WCF client to connect to an ASMX service. Changing the client configuration with maxStringContentLength fxed the problem. Thanks!
Andomar
-1 - there is nothing wrong with doing what the OP did and using a WCF client to consume a WCF service. His fix was correct - change the parameter in the client, which is where the exception was coming from.
John Saunders
@John: I agree with you but I don't see any relation between my answer and your comment.
Ladislav Mrnka
@Ladislav: sorry, but your answer is so confusing that I'm going to leave the -1. You seem to be saying that one cannot mix the two.
John Saunders
@John: Ok, thanks for warning - probably problem with my English because I didn't mean it with my answer. I just wanted to point out that when you have ASMX web service you cannot use WCF configuration to change its behavior. I didn't mean that you cannot consume ASMX web service with WCF client.
Ladislav Mrnka
@Ladislav: if you will edit your answer to include what you said in the last comment, i will remove the downvote.
John Saunders