简体   繁体   中英

Configure endpoint for web service declared with WebService() attribute

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM