开发者

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 m开发者_高级运维axStringContentLength 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜